Skip to content

Commit 866d7a8

Browse files
committed
Merge branch 'PHP-8.5' into PHP-8.6
* PHP-8.5: ext/snmp: Copy the context name in SNMP::setSecurity()
2 parents 84570db + 9afb52d commit 866d7a8

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

‎ext/snmp/snmp.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ static void snmp_session_free(php_snmp_session **session) /* {{{ */
169169
PHP_SNMP_SESSION_FREE(community);
170170
PHP_SNMP_SESSION_FREE(securityName);
171171
PHP_SNMP_SESSION_FREE(contextEngineID);
172+
PHP_SNMP_SESSION_FREE(contextName);
172173
efree(*session);
173174
*session = NULL;
174175
}
@@ -1243,7 +1244,10 @@ static ZEND_ATTRIBUTE_NONNULL_ARGS(2) bool snmp_session_set_security(struct snmp
12431244

12441245
/* Setting contextName if specified */
12451246
if (contextName) {
1246-
session->contextName = ZSTR_VAL(contextName);
1247+
if (session->contextName) {
1248+
efree(session->contextName);
1249+
}
1250+
session->contextName = estrndup(ZSTR_VAL(contextName), ZSTR_LEN(contextName));
12471251
session->contextNameLen = ZSTR_LEN(contextName);
12481252
}
12491253

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
SNMP::setSecurity() - the context name is copied
3+
--EXTENSIONS--
4+
snmp
5+
--SKIPIF--
6+
<?php
7+
require_once(__DIR__.'/skipif.inc');
8+
?>
9+
--FILE--
10+
<?php
11+
require_once(__DIR__.'/snmp_include.inc');
12+
13+
$session = new SNMP(SNMP::VERSION_3, $hostname, $rwuser, $timeout, $retries);
14+
$context = str_repeat('c', 5) . random_int(10, 99);
15+
$session->setSecurity('authPriv', 'MD5', $auth_pass, 'AES', $priv_pass, $context);
16+
unset($context);
17+
// The agent does not know this context, only the lifetime of the name matters.
18+
var_dump(@$session->get('.1.3.6.1.2.1.1.1.0'));
19+
$session->close();
20+
?>
21+
--EXPECT--
22+
bool(false)

0 commit comments

Comments
 (0)