Skip to content

Commit a3a3964

Browse files
committed
Fix oss-fuzz #61712: assertion failure with error handler during binary op
Because the error handler is invoked after the property is updated, the error handler has the opportunity to remove it before the property is returned. Switching the order around fixes this issue. The comments mention that the current ordering prevents overwriting the EG(std_property_info) field in the error handler. EG(std_property_info) no longer exists as it was removed in 7471c21. Back then a global was used to store the returned property info, but as this is no longer the case there is no longer a need to protect against overwriting a global. Closes GH-12062.
1 parent 1413787 commit a3a3964

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ PHP NEWS
88
(Jakub Zelenka)
99
. Fixed bug GH-11790 (On riscv64 require libatomic if actually needed).
1010
(Jeremie Courreges-Anglas)
11+
. Fixed oss-fuzz #61712 (assertion failure with error handler during binary
12+
op). (nielsdos)
1113

1214
- DOM:
1315
. Fixed GH-11952 (Confusing warning when blocking entity loading via

Zend/tests/oss_fuzz_61712.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
OSS-Fuzz #61712 (assertion failure with error handler during binary op)
3+
--FILE--
4+
<?php
5+
#[AllowDynamicProperties]
6+
class C {
7+
function error($_, $msg) {
8+
echo $msg, "\n";
9+
unset($this->a);
10+
}
11+
}
12+
13+
$c = new C;
14+
set_error_handler([$c, 'error']);
15+
$c->a %= 10;
16+
var_dump($c->a);
17+
?>
18+
--EXPECT--
19+
Undefined property: C::$a
20+
int(0)

Zend/zend_object_handlers.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,12 +1160,10 @@ ZEND_API zval *zend_std_get_property_ptr_ptr(zend_object *zobj, zend_string *nam
11601160
if (UNEXPECTED(!zobj->properties)) {
11611161
rebuild_object_properties(zobj);
11621162
}
1163-
retval = zend_hash_update(zobj->properties, name, &EG(uninitialized_zval));
1164-
/* Notice is thrown after creation of the property, to avoid EG(std_property_info)
1165-
* being overwritten in an error handler. */
11661163
if (UNEXPECTED(type == BP_VAR_RW || type == BP_VAR_R)) {
11671164
zend_error(E_WARNING, "Undefined property: %s::$%s", ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name));
11681165
}
1166+
retval = zend_hash_update(zobj->properties, name, &EG(uninitialized_zval));
11691167
}
11701168
} else if (zobj->ce->__get == NULL) {
11711169
retval = &EG(error_zval);

0 commit comments

Comments
 (0)