Skip to content

Commit f1fd1ab

Browse files
committed
Fix segfault when evaluating const expr default value of child prop with added hooks
Fixes oss-fuzz #403816122
1 parent d4eb6a4 commit f1fd1ab

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

Zend/tests/oss-fuzz-403816122.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
OSS-Fuzz #403816122: Segfault when initializing default properties of child prop with added hooks
3+
--FILE--
4+
<?php
5+
6+
const X = 'x';
7+
8+
class P {
9+
public $prop;
10+
}
11+
12+
class C extends P {
13+
public $prop = X {
14+
get => 'y';
15+
}
16+
}
17+
18+
var_dump((new C)->prop);
19+
20+
?>
21+
--EXPECT--
22+
string(1) "y"

Zend/zend_API.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1613,8 +1613,12 @@ ZEND_API zend_result zend_update_class_constants(zend_class_entry *class_type) /
16131613
/* Use the default properties table to also update initializers of private properties
16141614
* that have been shadowed in a child class. */
16151615
for (uint32_t i = 0; i < class_type->default_properties_count; i++) {
1616-
val = &default_properties_table[i];
16171616
prop_info = class_type->properties_info_table[i];
1617+
if (!prop_info) {
1618+
continue;
1619+
}
1620+
1621+
val = &default_properties_table[OBJ_PROP_TO_NUM(prop_info->offset)];
16181622
if (Z_TYPE_P(val) == IS_CONSTANT_AST
16191623
&& UNEXPECTED(update_property(val, prop_info) != SUCCESS)) {
16201624
return FAILURE;

0 commit comments

Comments
 (0)