com php-src: Fix ref ID handling when serializing $GLOBALS: ext/standard/tests/serialize/serialize_globals_var_refs .phpt ext/standard/var.c

From: Date: Mon, 08 Oct 2018 11:16:23 +0000
Subject: com php-src: Fix ref ID handling when serializing $GLOBALS: ext/standard/tests/serialize/serialize_globals_var_refs .phpt ext/standard/var.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-103397@lists.php.net to get a copy of this message
Commit: d982bbe175b6f4487683f538f2dc8aca4aef4a6b Author: Nikita Popov <nikita.ppv@gmail.com> Mon, 8 Oct 2018 13:14:54 +0200 Parents: c5df679ca8b1373e3f2a47aeba5b37da74f993de Branches: PHP-7.3 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=d982bbe175b6f4487683f538f2dc8aca4aef4a6b Log: Fix ref ID handling when serializing $GLOBALS This was already broken previously, but in PHP 7.3 stricter validation during unserialization made this into an error. Changed paths: A ext/standard/tests/serialize/serialize_globals_var_refs.phpt M ext/standard/var.c Diff: diff --git a/ext/standard/tests/serialize/serialize_globals_var_refs.phpt b/ext/standard/tests/serialize/serialize_globals_var_refs.phpt new file mode 100644 index 0000000...3f03cc2 --- /dev/null +++ b/ext/standard/tests/serialize/serialize_globals_var_refs.phpt @@ -0,0 +1,22 @@ +--TEST-- +Reference IDs should be correctly generated when $GLOBALS is serialized +--FILE-- +<?php + +$obj = new stdClass; +$obj2 = new stdClass; +$obj2->obj = $obj; +$s = serialize($GLOBALS); +$globals = unserialize($s); +var_dump($obj); +var_dump($obj2); + +?> +--EXPECT-- +object(stdClass)#1 (0) { +} +object(stdClass)#2 (1) { + ["obj"]=> + object(stdClass)#1 (0) { + } +} diff --git a/ext/standard/var.c b/ext/standard/var.c index e4c7932..77b290a6 100644 --- a/ext/standard/var.c +++ b/ext/standard/var.c @@ -959,9 +959,9 @@ again: /* we should still add element even if it's not OK, * since we already wrote the length of the array before */ if (Z_TYPE_P(data) == IS_ARRAY) { - if (Z_TYPE_P(data) == IS_ARRAY - && (UNEXPECTED(Z_IS_RECURSIVE_P(data)) - || UNEXPECTED(Z_TYPE_P(struc) == IS_ARRAY && Z_ARR_P(data) == Z_ARR_P(struc)))) { + if (UNEXPECTED(Z_IS_RECURSIVE_P(data)) + || UNEXPECTED(Z_TYPE_P(struc) == IS_ARRAY && Z_ARR_P(data) == Z_ARR_P(struc))) { + php_add_var_hash(var_hash, struc); smart_str_appendl(buf, "N;", 2); } else { if (Z_REFCOUNTED_P(data)) {

« previous php.cvs (#103397) next »