Skip to content

Commit 8347740

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Fix double-free of doc_comment when overriding static property via trait
2 parents 80b4c73 + 4f1f77c commit 8347740

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ PHP NEWS
66
. Fixed double-free of non-interned enum case name. (ilutov)
77
. Fixed bug GH-12457 (Incorrect result of stripos with single character
88
needle). (SakiTakamachi)
9+
. Fixed bug GH-12468 (Double-free of doc_comment when overriding static
10+
property via trait). (ilutov)
911

1012
- DOM:
1113
. Fix registerNodeClass with abstract class crashing. (nielsdos)

Zend/tests/gh12468_1.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
GH-12468: Double-free of doc_comment when overriding static property via trait
3+
--FILE--
4+
<?php
5+
trait T {
6+
/** some doc */
7+
static protected $a = 0;
8+
}
9+
class A {
10+
use T;
11+
}
12+
class B extends A {
13+
use T;
14+
}
15+
?>
16+
===DONE===
17+
--EXPECT--
18+
===DONE===

Zend/tests/gh12468_2.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
GH-12468: Double-free of doc_comment when overriding static property via trait
3+
--FILE--
4+
<?php
5+
trait T {
6+
/** some doc */
7+
static protected $a = 0;
8+
}
9+
class A {
10+
/** some doc */
11+
static protected $a = 0;
12+
}
13+
class B extends A {
14+
use T;
15+
}
16+
?>
17+
===DONE===
18+
--EXPECT--
19+
===DONE===

Zend/zend_API.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4332,7 +4332,7 @@ ZEND_API zend_property_info *zend_declare_typed_property(zend_class_entry *ce, z
43324332
(property_info_ptr->flags & ZEND_ACC_STATIC) != 0) {
43334333
property_info->offset = property_info_ptr->offset;
43344334
zval_ptr_dtor(&ce->default_static_members_table[property_info->offset]);
4335-
if (property_info_ptr->doc_comment) {
4335+
if (property_info_ptr->doc_comment && property_info_ptr->ce == ce) {
43364336
zend_string_release(property_info_ptr->doc_comment);
43374337
}
43384338
zend_hash_del(&ce->properties_info, name);
@@ -4353,7 +4353,7 @@ ZEND_API zend_property_info *zend_declare_typed_property(zend_class_entry *ce, z
43534353
(property_info_ptr->flags & ZEND_ACC_STATIC) == 0) {
43544354
property_info->offset = property_info_ptr->offset;
43554355
zval_ptr_dtor(&ce->default_properties_table[OBJ_PROP_TO_NUM(property_info->offset)]);
4356-
if (property_info_ptr->doc_comment) {
4356+
if (property_info_ptr->doc_comment && property_info_ptr->ce == ce) {
43574357
zend_string_release_ex(property_info_ptr->doc_comment, 1);
43584358
}
43594359
zend_hash_del(&ce->properties_info, name);

0 commit comments

Comments
 (0)