Skip to content

Commit 8a392ed

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. Closes GH-12114
1 parent d7273c5 commit 8a392ed

8 files changed

+125
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ PHP NEWS
1010
closures). (ilutov)
1111
. Fixed bug GH-12060 (Internal iterator rewind handler is called twice).
1212
(ju1ius)
13+
. Fixed OSS Fuzz #61865 (Undef variable in ++/-- for declared property
14+
that is unset in error handler). (Girgias)
1315

1416

1517
- FPM:
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)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Unset declared property converted to object in error handler
3+
--FILE--
4+
<?php
5+
class C {
6+
public $a;
7+
function errorHandler() {
8+
$this->a = new stdClass();
9+
}
10+
}
11+
$c = new C;
12+
set_error_handler([$c,'errorHandler']);
13+
unset($c->a);
14+
15+
try {
16+
(++$c->a);
17+
} catch (\TypeError $e) {
18+
echo $e->getMessage(), PHP_EOL;
19+
}
20+
var_dump($c->a);
21+
?>
22+
--EXPECT--
23+
Cannot increment stdClass
24+
object(stdClass)#2 (0) {
25+
}

Zend/zend_object_handlers.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,8 +1117,11 @@ 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+
/* An error handler may set the property */
1122+
if (EXPECTED(Z_TYPE_P(retval) == IS_UNDEF)) {
1123+
ZVAL_NULL(retval);
1124+
}
11221125
}
11231126
} else if (prop_info && UNEXPECTED(prop_info->flags & ZEND_ACC_READONLY)) {
11241127
/* Readonly property, delegate to read_property + write_property. */

0 commit comments

Comments
 (0)