Skip to content

Commit da6f123

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: Fix by-ref assignment to uninitialized hooked backing value
2 parents 5fb8165 + 0efecbc commit da6f123

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ PHP NEWS
1616
. Fixed bug GH-20895 (ReflectionProperty does not return the PHPDoc of a
1717
property if it contains an attribute with a Closure). (timwolla)
1818
. Fixed bug GH-20766 (Use-after-free in FE_FREE with GC interaction). (Bob)
19+
. Fix OSS-Fuzz #471486164 (Broken by-ref assignment to uninitialized hooked
20+
backing value). (ilutov)
1921

2022
- Date:
2123
. Update timelib to 2022.16. (Derick)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
OSS-Fuzz #471486164: get_property_ptr_ptr() on uninitialized hooked property
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public $a {
8+
get => $this->a;
9+
set { $this->a = &$value; }
10+
}
11+
public $x = 1;
12+
}
13+
14+
$proxy = (new ReflectionClass(C::class))->newLazyProxy(function ($proxy) {
15+
$proxy->a = 1;
16+
return new C;
17+
});
18+
var_dump($proxy->x);
19+
20+
?>
21+
--EXPECT--
22+
int(1)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
OSS-Fuzz #471486164: get_property_ptr_ptr() on uninitialized hooked property
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public int $a {
8+
get => $this->a;
9+
set {
10+
global $ref;
11+
$this->a = &$ref;
12+
}
13+
}
14+
}
15+
16+
$ref = 1;
17+
$proxy = new C;
18+
$proxy->a = 1;
19+
var_dump($proxy->a);
20+
$ref++;
21+
var_dump($proxy->a);
22+
23+
?>
24+
--EXPECT--
25+
int(1)
26+
int(2)

Zend/zend_object_handlers.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,7 @@ ZEND_API zval *zend_std_get_property_ptr_ptr(zend_object *zobj, zend_string *nam
13961396
property_offset = zend_get_property_offset(zobj->ce, name, (zobj->ce->__get != NULL), cache_slot, &prop_info);
13971397

13981398
if (EXPECTED(IS_VALID_PROPERTY_OFFSET(property_offset))) {
1399+
try_again:
13991400
retval = OBJ_PROP(zobj, property_offset);
14001401
if (UNEXPECTED(Z_TYPE_P(retval) == IS_UNDEF)) {
14011402
if (EXPECTED(!zobj->ce->__get) ||
@@ -1475,7 +1476,15 @@ ZEND_API zval *zend_std_get_property_ptr_ptr(zend_object *zobj, zend_string *nam
14751476
}
14761477
retval = zend_hash_add(zobj->properties, name, &EG(uninitialized_zval));
14771478
}
1478-
} else if (!IS_HOOKED_PROPERTY_OFFSET(property_offset) && zobj->ce->__get == NULL) {
1479+
} else if (IS_HOOKED_PROPERTY_OFFSET(property_offset)) {
1480+
if (!(prop_info->flags & ZEND_ACC_VIRTUAL) && !zend_should_call_hook(prop_info, zobj)) {
1481+
property_offset = prop_info->offset;
1482+
if (!ZEND_TYPE_IS_SET(prop_info->type)) {
1483+
prop_info = NULL;
1484+
}
1485+
goto try_again;
1486+
}
1487+
} else if (zobj->ce->__get == NULL) {
14791488
retval = &EG(error_zval);
14801489
}
14811490

0 commit comments

Comments
 (0)