Skip to content

Commit 962e84f

Browse files
committed
Fix OSS Fuzz #61865: Undef variable in ++/-- for declared property that is unset in error handler
Reorder when we assign the property value to NULL which is identical to a3a3964 Just for the declared property case instead of dynamic.
1 parent 013bb57 commit 962e84f

6 files changed

+97
-1
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
OSS Fuzz #61865: Undef variable in ++/-- for declared property that is unset in error handler
3+
--FILE--
4+
<?php
5+
class C {
6+
public $a;
7+
function errorHandler($errno, $errstr) {
8+
unset($this->a);
9+
}
10+
}
11+
$c = new C;
12+
set_error_handler([$c,'errorHandler']);
13+
unset($c->a);
14+
$c->a += 5;
15+
var_dump($c->a);
16+
?>
17+
--EXPECT--
18+
int(5)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
OSS Fuzz #61865: Undef variable in ++/-- for declared property that is unset in error handler
3+
--FILE--
4+
<?php
5+
class C {
6+
public $a;
7+
function errorHandler($errno, $errstr) {
8+
unset($this->a);
9+
}
10+
}
11+
$c = new C;
12+
set_error_handler([$c,'errorHandler']);
13+
unset($c->a);
14+
$v = ($c->a--);
15+
var_dump($c->a);
16+
var_dump($v);
17+
?>
18+
--EXPECT--
19+
NULL
20+
NULL
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
OSS Fuzz #61865: Undef variable in ++/-- for declared property that is unset in error handler
3+
--FILE--
4+
<?php
5+
class C {
6+
public $a;
7+
function errorHandler($errno, $errstr) {
8+
unset($this->a);
9+
}
10+
}
11+
$c = new C;
12+
set_error_handler([$c,'errorHandler']);
13+
unset($c->a);
14+
$v = ($c->a++);
15+
var_dump($c->a);
16+
var_dump($v);
17+
?>
18+
--EXPECT--
19+
int(1)
20+
NULL
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
OSS Fuzz #61865: Undef variable in ++/-- for declared property that is unset in error handler
3+
--FILE--
4+
<?php
5+
class C {
6+
public $a;
7+
function errorHandler($errno, $errstr) {
8+
unset($this->a);
9+
}
10+
}
11+
$c = new C;
12+
set_error_handler([$c,'errorHandler']);
13+
unset($c->a);
14+
(--$c->a);
15+
var_dump($c->a);
16+
?>
17+
--EXPECT--
18+
NULL
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
OSS Fuzz #61865: Undef variable in ++/-- for declared property that is unset in error handler
3+
--FILE--
4+
<?php
5+
class C {
6+
public $a;
7+
function errorHandler($errno, $errstr) {
8+
unset($this->a);
9+
}
10+
}
11+
$c = new C;
12+
set_error_handler([$c,'errorHandler']);
13+
unset($c->a);
14+
(++$c->a);
15+
var_dump($c->a);
16+
?>
17+
--EXPECT--
18+
int(1)

Zend/zend_object_handlers.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,8 +1117,10 @@ ZEND_API zval *zend_std_get_property_ptr_ptr(zend_object *zobj, zend_string *nam
11171117
ZSTR_VAL(name));
11181118
retval = &EG(error_zval);
11191119
} else {
1120-
ZVAL_NULL(retval);
11211120
zend_error(E_WARNING, "Undefined property: %s::$%s", ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name));
1121+
/* We set the retval to null AFTER the warning so that an error handler cannot mess
1122+
* with the property value... */
1123+
ZVAL_NULL(retval);
11221124
}
11231125
} else if (prop_info && UNEXPECTED(prop_info->flags & ZEND_ACC_READONLY)) {
11241126
/* Readonly property, delegate to read_property + write_property. */

0 commit comments

Comments
 (0)