Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion ext/snmp/snmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ static void netsnmp_session_free(php_snmp_session **session) /* {{{ */
PHP_SNMP_SESSION_FREE(community);
PHP_SNMP_SESSION_FREE(securityName);
PHP_SNMP_SESSION_FREE(contextEngineID);
PHP_SNMP_SESSION_FREE(contextName);
efree(*session);
*session = NULL;
}
Expand Down Expand Up @@ -1169,7 +1170,10 @@ static ZEND_ATTRIBUTE_NONNULL_ARGS(2) bool netsnmp_session_set_security(struct s

/* Setting contextName if specified */
if (contextName) {
session->contextName = ZSTR_VAL(contextName);
if (session->contextName) {
efree(session->contextName);
}
session->contextName = estrndup(ZSTR_VAL(contextName), ZSTR_LEN(contextName));
session->contextNameLen = ZSTR_LEN(contextName);
}

Expand Down
22 changes: 22 additions & 0 deletions ext/snmp/tests/snmp-object-setSecurity-contextName.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
SNMP::setSecurity() - the context name is copied
--EXTENSIONS--
snmp
--SKIPIF--
<?php
require_once(__DIR__.'/skipif.inc');
?>
--FILE--
<?php
require_once(__DIR__.'/snmp_include.inc');

$session = new SNMP(SNMP::VERSION_3, $hostname, $rwuser, $timeout, $retries);
$context = str_repeat('c', 5) . random_int(10, 99);
$session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, $context);
unset($context);
// The agent does not know this context, only the lifetime of the name matters.
var_dump(@$session->get('.1.3.6.1.2.1.1.1.0'));
$session->close();
?>
--EXPECT--
bool(false)
Loading