summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2020-03-05 14:57:27 +0100
committerChristoph M. Becker <cmbecker69@gmx.de>2020-03-06 09:09:49 +0100
commitb84277297ae18f11055a5731a881a347df8d76b9 (patch)
tree97a4ef7146167422554769bd3cdc1a575418c5cf
parent9dda3b9eb2d47bda7805f02c417ead54487d655e (diff)
downloadphp-git-b84277297ae18f11055a5731a881a347df8d76b9.tar.gz
Fix #75673: SplStack::unserialize() behavior
Even though `SplStack::unserialize()` is not supposed to be called on an already constructed instance, it is probably better if the method clears the stack before actually unserializing.
-rw-r--r--NEWS3
-rw-r--r--ext/spl/spl_dllist.c6
-rw-r--r--ext/spl/tests/bug75673.phpt19
3 files changed, 28 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 8f89531714..f3750061e1 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,9 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 7.3.17
+- Spl:
+ . Fixed bug #75673 (SplStack::unserialize() behavior). (cmb)
+
19 Mar 2020, PHP 7.3.16
- Core:
diff --git a/ext/spl/spl_dllist.c b/ext/spl/spl_dllist.c
index ba9488abfc..9919b1aa63 100644
--- a/ext/spl/spl_dllist.c
+++ b/ext/spl/spl_dllist.c
@@ -1185,6 +1185,12 @@ SPL_METHOD(SplDoublyLinkedList, unserialize)
return;
}
+ while (intern->llist->count > 0) {
+ zval tmp;
+ spl_ptr_llist_pop(intern->llist, &tmp);
+ zval_ptr_dtor(&tmp);
+ }
+
s = p = (const unsigned char*)buf;
PHP_VAR_UNSERIALIZE_INIT(var_hash);
diff --git a/ext/spl/tests/bug75673.phpt b/ext/spl/tests/bug75673.phpt
new file mode 100644
index 0000000000..76fe3745fb
--- /dev/null
+++ b/ext/spl/tests/bug75673.phpt
@@ -0,0 +1,19 @@
+--TEST--
+Bug #75673 (SplStack::unserialize() behavior)
+--FILE--
+<?php
+$stack = new SplStack();
+$stack->push("one");
+$stack->push("two");
+
+$serialized = $stack->serialize();
+var_dump($stack->count());
+$stack->unserialize($serialized);
+var_dump($stack->count());
+$stack->unserialize($serialized);
+var_dump($stack->count());
+?>
+--EXPECT--
+int(2)
+int(2)
+int(2)