]> granicus.if.org Git - php/commitdiff
Fix ref ID handling when serializing $GLOBALS
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 8 Oct 2018 11:14:54 +0000 (13:14 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 8 Oct 2018 11:16:23 +0000 (13:16 +0200)
This was already broken previously, but in PHP 7.3 stricter
validation during unserialization made this into an error.

ext/standard/tests/serialize/serialize_globals_var_refs.phpt [new file with mode: 0644]
ext/standard/var.c

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 (file)
index 0000000..3f03cc2
--- /dev/null
@@ -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) {
+  }
+}
index e4c79328680ac68406277848e7498ad933be94bb..77b290a6cc7cd03bf9baa265344b1f407c29a7a9 100644 (file)
@@ -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)) {