Skip to content

Commit f39b029

Browse files
committed
Merge branch 'PHP-8.3'
* PHP-8.3: Fix double-free of doc_comment when overriding static property via trait
2 parents cdfa016 + 8347740 commit f39b029

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

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
@@ -4341,7 +4341,7 @@ ZEND_API zend_property_info *zend_declare_typed_property(zend_class_entry *ce, z
43414341
ZEND_ASSERT(property_info_ptr->flags & ZEND_ACC_STATIC);
43424342
property_info->offset = property_info_ptr->offset;
43434343
zval_ptr_dtor(&ce->default_static_members_table[property_info->offset]);
4344-
if (property_info_ptr->doc_comment) {
4344+
if (property_info_ptr->doc_comment && property_info_ptr->ce == ce) {
43454345
zend_string_release(property_info_ptr->doc_comment);
43464346
}
43474347
zend_hash_del(&ce->properties_info, name);
@@ -4362,7 +4362,7 @@ ZEND_API zend_property_info *zend_declare_typed_property(zend_class_entry *ce, z
43624362
ZEND_ASSERT(!(property_info_ptr->flags & ZEND_ACC_STATIC));
43634363
property_info->offset = property_info_ptr->offset;
43644364
zval_ptr_dtor(&ce->default_properties_table[OBJ_PROP_TO_NUM(property_info->offset)]);
4365-
if (property_info_ptr->doc_comment) {
4365+
if (property_info_ptr->doc_comment && property_info_ptr->ce == ce) {
43664366
zend_string_release_ex(property_info_ptr->doc_comment, 1);
43674367
}
43684368
zend_hash_del(&ce->properties_info, name);

0 commit comments

Comments
 (0)