[php-src] master: Merge branch 'PHP-8.5'
| From: | David Carlier | Date: | Mon, 07 Sep 2026 20:10:06 +0000 |
| Subject: | [php-src] master: Merge branch 'PHP-8.5' | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141115@lists.php.net to get a copy of this message | ||
Author: David Carlier (devnexen)
Date: 2026-09-07T21:07:48+01:00
Commit: https://github.com/php/php-src/commit/65d9f8a3a98238a4b76ea1ffdd803673528c7b4e
Raw diff: https://github.com/php/php-src/commit/65d9f8a3a98238a4b76ea1ffdd803673528c7b4e.diff
Merge branch 'PHP-8.5'
* PHP-8.5:
Fix GH-23453: bad free with a context engine ID longer than 32 bytes
# Conflicts:
# ext/snmp/snmp.c
Changed paths:
A ext/snmp/tests/gh23453.phpt
M ext/snmp/snmp.c
Diff:
diff --git a/ext/snmp/snmp.c b/ext/snmp/snmp.c
index 94b7d803a030..0c0607392366 100644
--- a/ext/snmp/snmp.c
+++ b/ext/snmp/snmp.c
@@ -1158,7 +1158,8 @@ static bool snmp_session_set_contextEngineID(struct snmp_session *s,
zend_string
size_t ebuf_len = 32, eout_len = 0;
uint8_t *ebuf = (uint8_t *) emalloc(ebuf_len);
- if (!snmp_hex_to_binary(&ebuf, &ebuf_len, &eout_len, 1, ZSTR_VAL(contextEngineID))) {
+ /* Disallow reallocation: ebuf comes from emalloc() and net-snmp would realloc() it. */
+ if (!snmp_hex_to_binary(&ebuf, &ebuf_len, &eout_len, 0, ZSTR_VAL(contextEngineID))) {
zend_argument_value_error(context_engine_id_arg_num, "must be a valid context engine
ID");
efree(ebuf);
return false;
diff --git a/ext/snmp/tests/gh23453.phpt b/ext/snmp/tests/gh23453.phpt
new file mode 100644
index 000000000000..19327791fa9a
--- /dev/null
+++ b/ext/snmp/tests/gh23453.phpt
@@ -0,0 +1,19 @@
+--TEST--
+GH-23453 (SNMP::setSecurity() frees a non-malloced address with a context engine ID longer than 32
bytes)
+--EXTENSIONS--
+snmp
+--FILE--
+<?php
+$session = new SNMP(SNMP::VERSION_3, 'localhost', 'user');
+
+// 32 bytes is the maximum length of a context engine ID
+var_dump($session->setSecurity('authPriv', 'SHA',
'authpassword12345', 'AES', 'privpassword12345',
'myContext', str_repeat('aa', 32)));
+try {
+ var_dump($session->setSecurity('authPriv', 'SHA',
'authpassword12345', 'AES', 'privpassword12345',
'myContext', str_repeat('aa', 33)));
+} catch (\ValueError $e) {
+ echo $e::class, ': ', $e->getMessage(), \PHP_EOL;
+}
+?>
+--EXPECT--
+bool(true)
+ValueError: SNMP::setSecurity(): Argument #7 ($contextEngineId) must be a valid context engine ID