Skip to content

Commit 4f1f77c

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Fix double-free of doc_comment when overriding static property via trait
2 parents 736032f + af3d2f7 commit 4f1f77c

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
@@ -4199,7 +4199,7 @@ ZEND_API zend_property_info *zend_declare_typed_property(zend_class_entry *ce, z
41994199
(property_info_ptr->flags & ZEND_ACC_STATIC) != 0) {
42004200
property_info->offset = property_info_ptr->offset;
42014201
zval_ptr_dtor(&ce->default_static_members_table[property_info->offset]);
4202-
if (property_info_ptr->doc_comment) {
4202+
if (property_info_ptr->doc_comment && property_info_ptr->ce == ce) {
42034203
zend_string_release(property_info_ptr->doc_comment);
42044204
}
42054205
zend_hash_del(&ce->properties_info, name);
@@ -4220,7 +4220,7 @@ ZEND_API zend_property_info *zend_declare_typed_property(zend_class_entry *ce, z
42204220
(property_info_ptr->flags & ZEND_ACC_STATIC) == 0) {
42214221
property_info->offset = property_info_ptr->offset;
42224222
zval_ptr_dtor(&ce->default_properties_table[OBJ_PROP_TO_NUM(property_info->offset)]);
4223-
if (property_info_ptr->doc_comment) {
4223+
if (property_info_ptr->doc_comment && property_info_ptr->ce == ce) {
42244224
zend_string_release_ex(property_info_ptr->doc_comment, 1);
42254225
}
42264226
zend_hash_del(&ce->properties_info, name);

0 commit comments

Comments
 (0)