Skip to content

Fix OSS Fuzz #61865: Undef variable in ++/-- for declared property that is unset in error handler #12114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
OSS Fuzz #61865: Undef variable in ++/-- for declared property that is unset in error handler
--FILE--
<?php
class C {
public $a;
function errorHandler($errno, $errstr) {
unset($this->a);
}
}
$c = new C;
set_error_handler([$c,'errorHandler']);
unset($c->a);
$c->a += 5;
var_dump($c->a);
?>
--EXPECT--
int(5)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
OSS Fuzz #61865: Undef variable in ++/-- for declared property that is unset in error handler
--FILE--
<?php
class C {
public $a;
function errorHandler($errno, $errstr) {
unset($this->a);
}
}
$c = new C;
set_error_handler([$c,'errorHandler']);
unset($c->a);
$v = ($c->a--);
var_dump($c->a);
var_dump($v);
?>
--EXPECT--
NULL
NULL
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
OSS Fuzz #61865: Undef variable in ++/-- for declared property that is unset in error handler
--FILE--
<?php
class C {
public $a;
function errorHandler($errno, $errstr) {
unset($this->a);
}
}
$c = new C;
set_error_handler([$c,'errorHandler']);
unset($c->a);
$v = ($c->a++);
var_dump($c->a);
var_dump($v);
?>
--EXPECT--
int(1)
NULL
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
OSS Fuzz #61865: Undef variable in ++/-- for declared property that is unset in error handler
--FILE--
<?php
class C {
public $a;
function errorHandler($errno, $errstr) {
unset($this->a);
}
}
$c = new C;
set_error_handler([$c,'errorHandler']);
unset($c->a);
(--$c->a);
var_dump($c->a);
?>
--EXPECT--
NULL
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
OSS Fuzz #61865: Undef variable in ++/-- for declared property that is unset in error handler
--FILE--
<?php
class C {
public $a;
function errorHandler($errno, $errstr) {
unset($this->a);
}
}
$c = new C;
set_error_handler([$c,'errorHandler']);
unset($c->a);
(++$c->a);
var_dump($c->a);
?>
--EXPECT--
int(1)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
Unset declared property converted to object in error handler
--FILE--
<?php
class C {
public $a;
function errorHandler() {
$this->a = new stdClass();
}
}
$c = new C;
set_error_handler([$c,'errorHandler']);
unset($c->a);

try {
(++$c->a);
} catch (\TypeError $e) {
echo $e->getMessage(), PHP_EOL;
}
var_dump($c->a);
?>
--EXPECT--
Cannot increment stdClass
object(stdClass)#2 (0) {
}
5 changes: 4 additions & 1 deletion Zend/zend_object_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -1117,8 +1117,11 @@ ZEND_API zval *zend_std_get_property_ptr_ptr(zend_object *zobj, zend_string *nam
ZSTR_VAL(name));
retval = &EG(error_zval);
} else {
ZVAL_NULL(retval);
zend_error(E_WARNING, "Undefined property: %s::$%s", ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name));
/* An error handler may set the property */
if (EXPECTED(Z_TYPE_P(retval) == IS_UNDEF)) {
ZVAL_NULL(retval);
}
}
} else if (prop_info && UNEXPECTED(prop_info->flags & ZEND_ACC_READONLY)) {
/* Readonly property, delegate to read_property + write_property. */
Expand Down