1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fix Randomizer::__serialize() wrt INDIRECTs

First follow-up to GH-20102.
INDIRECTs must never get exposed to userland. The simple solution is to
duplicate the properties array.

Closes GH-20103.
This commit is contained in:
Niels Dossche
2025-10-08 09:31:00 +02:00
parent b16761ec11
commit c5fa7696e6
3 changed files with 22 additions and 2 deletions

3
NEWS
View File

@@ -7,6 +7,9 @@ PHP NEWS
. Fixed bug GH-20073 (Assertion failure in WeakMap offset operations on
reference). (nielsdos)
- Random:
. Fix Randomizer::__serialize() w.r.t. INDIRECTs. (nielsdos)
23 Oct 2025, PHP 8.3.27
- Core:

View File

@@ -468,8 +468,7 @@ PHP_METHOD(Random_Randomizer, __serialize)
ZEND_PARSE_PARAMETERS_NONE();
array_init(return_value);
ZVAL_ARR(&t, zend_std_get_properties(&randomizer->std));
Z_TRY_ADDREF(t);
ZVAL_ARR(&t, zend_array_dup(zend_std_get_properties(&randomizer->std)));
zend_hash_next_index_insert(Z_ARRVAL_P(return_value), &t);
}
/* }}} */

View File

@@ -0,0 +1,18 @@
--TEST--
Random: Engine: __serialize() must not expose INDIRECTs
--FILE--
<?php
$randomizer = new Random\Randomizer(null);
var_dump($randomizer->__serialize());
?>
--EXPECT--
array(1) {
[0]=>
array(1) {
["engine"]=>
object(Random\Engine\Secure)#2 (0) {
}
}
}