[php-src] master: Merge branch 'PHP-8.6'
| From: | David Carlier | Date: | Fri, 13 Nov 2026 06:23:02 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.6' | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-143680@lists.php.net to get a copy of this message | ||
Author: David Carlier (devnexen)
Date: 2026-11-13T06:21:10Z
Commit: https://github.com/php/php-src/commit/90917722e2a59f71849d4b5cad494af2a9f96cc4
Raw diff: https://github.com/php/php-src/commit/90917722e2a59f71849d4b5cad494af2a9f96cc4.diff
Merge branch 'PHP-8.6'
* PHP-8.6:
ext/snmp: Copy the context name in SNMP::setSecurity()
Changed paths:
A ext/snmp/tests/snmp-object-setSecurity-contextName.phpt
M ext/snmp/snmp.c
Diff:
diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c
index 1c0d8ed2f80a..354df8eae288 100644
--- a/ext/snmp/snmp.c
+++ b/ext/snmp/snmp.c
@@ -169,6 +169,7 @@ static void snmp_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;
}
@@ -1250,7 +1251,10 @@ static ZEND_ATTRIBUTE_NONNULL_ARGS(2) bool snmp_session_set_security(struct
snmp
/* 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);
}
diff --git a/ext/snmp/tests/snmp-object-setSecurity-contextName.phpt
b/ext/snmp/tests/snmp-object-setSecurity-contextName.phpt
new file mode 100644
index 000000000000..95055e2be8f3
--- /dev/null
+++ b/ext/snmp/tests/snmp-object-setSecurity-contextName.phpt
@@ -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)