Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Zend/tests/oss-fuzz-471486164-001.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
OSS-Fuzz #471486164: get_property_ptr_ptr() on uninitialized hooked property
--FILE--
<?php

class C {
public $a {
get => $this->a;
set { $this->a = &$value; }
}
public $x = 1;
}

$proxy = (new ReflectionClass(C::class))->newLazyProxy(function ($proxy) {
$proxy->a = 1;
return new C;
});
var_dump($proxy->x);

?>
--EXPECT--
int(1)
26 changes: 26 additions & 0 deletions Zend/tests/oss-fuzz-471486164-002.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
OSS-Fuzz #471486164: get_property_ptr_ptr() on uninitialized hooked property
--FILE--
<?php

class C {
public int $a {
get => $this->a;
set {
global $ref;
$this->a = &$ref;
}
}
}

$ref = 1;
$proxy = new C;
$proxy->a = 1;
var_dump($proxy->a);
$ref++;
var_dump($proxy->a);

?>
--EXPECT--
int(1)
int(2)
11 changes: 10 additions & 1 deletion Zend/zend_object_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1392,6 +1392,7 @@ ZEND_API zval *zend_std_get_property_ptr_ptr(zend_object *zobj, zend_string *nam
property_offset = zend_get_property_offset(zobj->ce, name, (zobj->ce->__get != NULL), cache_slot, &prop_info);

if (EXPECTED(IS_VALID_PROPERTY_OFFSET(property_offset))) {
try_again:
retval = OBJ_PROP(zobj, property_offset);
if (UNEXPECTED(Z_TYPE_P(retval) == IS_UNDEF)) {
if (EXPECTED(!zobj->ce->__get) ||
Expand Down Expand Up @@ -1471,7 +1472,15 @@ ZEND_API zval *zend_std_get_property_ptr_ptr(zend_object *zobj, zend_string *nam
}
retval = zend_hash_add(zobj->properties, name, &EG(uninitialized_zval));
}
} else if (!IS_HOOKED_PROPERTY_OFFSET(property_offset) && zobj->ce->__get == NULL) {
} else if (IS_HOOKED_PROPERTY_OFFSET(property_offset)) {
if (!(prop_info->flags & ZEND_ACC_VIRTUAL) && !zend_should_call_hook(prop_info, zobj)) {
property_offset = prop_info->offset;
if (!ZEND_TYPE_IS_SET(prop_info->type)) {
prop_info = NULL;
}
goto try_again;
}
} else if (zobj->ce->__get == NULL) {
retval = &EG(error_zval);
}

Expand Down
Loading