From f930d6ea0e8ca8723212ab234973d74dbccfc226 Mon Sep 17 00:00:00 2001 From: Xinchen Hui Date: Fri, 10 Jul 2015 16:33:13 +0800 Subject: [PATCH] Fixed Bug #69996 (Changing the property of a cloned object affects the original) --- NEWS | 2 ++ Zend/tests/bug69996.phpt | 25 +++++++++++++++++++++++++ Zend/zend_execute.c | 6 ++++++ 3 files changed, 33 insertions(+) create mode 100644 Zend/tests/bug69996.phpt diff --git a/NEWS b/NEWS index 547ed4667e..989c1cc271 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,8 @@ - Core: . Fixed bug #70012 (Exception lost with nested finally block). (Laruence) + . Fixed bug #69996 (Changing the property of a cloned object affects the + original). (Dmitry, Laruence) - Soap: . Fixed bug #70032 (make_http_soap_request calls diff --git a/Zend/tests/bug69996.phpt b/Zend/tests/bug69996.phpt new file mode 100644 index 0000000000..178e36837a --- /dev/null +++ b/Zend/tests/bug69996.phpt @@ -0,0 +1,25 @@ +--TEST-- +Bug #69996 (Changing the property of a cloned object affects the original) +--FILE-- +data); + $prepared->data = "bad"; + return $prepared; +} + +$cache = new stdClass(); +$cache->data = "good"; + +for ($i = 0; $i < 5; ++$i) { + method($cache); +} +?> +--EXPECT-- +string(4) "good" +string(4) "good" +string(4) "good" +string(4) "good" +string(4) "good" diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c index 257f627d22..98a7f2785b 100644 --- a/Zend/zend_execute.c +++ b/Zend/zend_execute.c @@ -1110,6 +1110,12 @@ fast_assign: } } else { if (EXPECTED(zobj->properties != NULL)) { + if (UNEXPECTED(GC_REFCOUNT(zobj->properties) > 1)) { + if (EXPECTED(!(GC_FLAGS(zobj->properties) & IS_ARRAY_IMMUTABLE))) { + GC_REFCOUNT(zobj->properties)--; + } + zobj->properties = zend_array_dup(zobj->properties); + } property = zend_hash_find(zobj->properties, Z_STR_P(property_name)); if (property) { goto fast_assign; -- 2.50.1