Skip to content

Commit e85550f

Browse files
committed
Merge branch 'PHP-8.5'
* PHP-8.5: Fix by-ref assignment to uninitialized hooked backing value
2 parents 6e6a850 + da6f123 commit e85550f

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed
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
@@ -1398,6 +1398,7 @@ ZEND_API zval *zend_std_get_property_ptr_ptr(zend_object *zobj, zend_string *nam
13981398
property_offset = zend_get_property_offset(zobj->ce, name, (zobj->ce->__get != NULL), cache_slot, &prop_info);
13991399

14001400
if (EXPECTED(IS_VALID_PROPERTY_OFFSET(property_offset))) {
1401+
try_again:
14011402
retval = OBJ_PROP(zobj, property_offset);
14021403
if (UNEXPECTED(Z_TYPE_P(retval) == IS_UNDEF)) {
14031404
if (EXPECTED(!zobj->ce->__get) ||
@@ -1477,7 +1478,15 @@ ZEND_API zval *zend_std_get_property_ptr_ptr(zend_object *zobj, zend_string *nam
14771478
}
14781479
retval = zend_hash_add(zobj->properties, name, &EG(uninitialized_zval));
14791480
}
1480-
} else if (!IS_HOOKED_PROPERTY_OFFSET(property_offset) && zobj->ce->__get == NULL) {
1481+
} else if (IS_HOOKED_PROPERTY_OFFSET(property_offset)) {
1482+
if (!(prop_info->flags & ZEND_ACC_VIRTUAL) && !zend_should_call_hook(prop_info, zobj)) {
1483+
property_offset = prop_info->offset;
1484+
if (!ZEND_TYPE_IS_SET(prop_info->type)) {
1485+
prop_info = NULL;
1486+
}
1487+
goto try_again;
1488+
}
1489+
} else if (zobj->ce->__get == NULL) {
14811490
retval = &EG(error_zval);
14821491
}
14831492

0 commit comments

Comments
 (0)