com php-src: Fixed bug #78787: NEWS Zend/tests/bug78787.phpt Zend/zend_inheritance.c
| From: | Nikita Popov | Date: | Wed, 06 Nov 2019 11:52:34 +0000 |
| Subject: | com php-src: Fixed bug #78787: NEWS Zend/tests/bug78787.phpt Zend/zend_inheritance.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-109194@lists.php.net to get a copy of this message | ||
Commit: 6d4965febdb1745444e7a3408fa7c01bcfc52b68
Author: Nikita Popov <nikita.ppv@gmail.com> Wed, 6 Nov 2019 12:51:25 +0100
Parents: 4c9ba3e0428693a89cc4beff5c8773e97075880a
Branches: PHP-7.3 PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=6d4965febdb1745444e7a3408fa7c01bcfc52b68
Log:
Fixed bug #78787
Not the first time inheritance of shadow properties causes an issue,
thankfully this whole concept is gone in PHP 7.4.
Bugs:
https://bugs.php.net/78787
Changed paths:
M NEWS
A Zend/tests/bug78787.phpt
M Zend/zend_inheritance.c
Diff:
diff --git a/NEWS b/NEWS
index f74a71fdcc9..2e67e596838 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,10 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 7.3.13
+- Core:
+ . Fixed bug #78787 (Segfault with trait overriding inherited private shadow
+ property). (Nikita)
+
21 Nov 2019, PHP 7.3.12
- Core:
diff --git a/Zend/tests/bug78787.phpt b/Zend/tests/bug78787.phpt
new file mode 100644
index 00000000000..91d5a9aa83d
--- /dev/null
+++ b/Zend/tests/bug78787.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Bug #78787: Segfault with trait overriding inherited private shadow property
+--FILE--
+<?php
+
+trait T {
+ private $prop;
+}
+class C1 {
+ /** Doc comment */
+ private $prop;
+}
+class C2 extends C1 {
+}
+class C3 extends C2 {
+ use T;
+}
+
+?>
+===DONE===
+--EXPECT--
+===DONE===
diff --git a/Zend/zend_inheritance.c b/Zend/zend_inheritance.c
index 0b0cb314b63..d271b741544 100644
--- a/Zend/zend_inheritance.c
+++ b/Zend/zend_inheritance.c
@@ -1595,10 +1595,14 @@ static void zend_do_traits_property_binding(zend_class_entry *ce) /* {{{ */
/* next: check for conflicts with current class */
if ((coliding_prop = zend_hash_find_ptr(&ce->properties_info, prop_name)) != NULL) {
if (coliding_prop->flags & ZEND_ACC_SHADOW) {
- zend_string_release_ex(coliding_prop->name, 0);
- if (coliding_prop->doc_comment) {
- zend_string_release_ex(coliding_prop->doc_comment, 0);
- }
+ /* Only free if shadow is coming from direct parent,
+ * otherwise these weren't copied in the first place. */
+ if (coliding_prop->ce == ce->parent) {
+ zend_string_release_ex(coliding_prop->name, 0);
+ if (coliding_prop->doc_comment) {
+ zend_string_release_ex(coliding_prop->doc_comment, 0);
+ }
+ }
zend_hash_del(&ce->properties_info, prop_name);
flags |= ZEND_ACC_CHANGED;
} else {