[php-src] PHP-8.5: Merge branch 'PHP-8.4' into PHP-8.5

From: Date: Mon, 07 Sep 2026 20:10:06 +0000
Subject: [php-src] PHP-8.5: Merge branch 'PHP-8.4' into PHP-8.5
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-141113@lists.php.net to get a copy of this message
Author: David Carlier (devnexen) Date: 2026-09-07T21:07:12+01:00 Commit: https://github.com/php/php-src/commit/b003ae80cf3fbe77342c58aaad121ff22c329a09 Raw diff: https://github.com/php/php-src/commit/b003ae80cf3fbe77342c58aaad121ff22c329a09.diff Merge branch 'PHP-8.4' into PHP-8.5 * PHP-8.4: Fix GH-23453: bad free with a context engine ID longer than 32 bytes 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 38cf82b62bd6..672ac9a94b4f 100644 --- a/ext/snmp/snmp.c +++ b/ext/snmp/snmp.c @@ -1130,7 +1130,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))) { // TODO Promote to Error? php_error_docref(NULL, E_WARNING, "Bad engine ID value '%s'", ZSTR_VAL(contextEngineID)); efree(ebuf); diff --git a/ext/snmp/tests/gh23453.phpt b/ext/snmp/tests/gh23453.phpt new file mode 100644 index 000000000000..aaa89baad182 --- /dev/null +++ b/ext/snmp/tests/gh23453.phpt @@ -0,0 +1,17 @@ +--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))); +var_dump($session->setSecurity('authPriv', 'SHA', 'authpassword12345', 'AES', 'privpassword12345', 'myContext', str_repeat('aa', 33))); +?> +--EXPECTF-- +bool(true) + +Warning: SNMP::setSecurity(): Bad engine ID value 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa' in %s on line %d +bool(false)

« previous php.cvs (#141113) next »