Skip to content

Commit 7925d21

Browse files
committed
Fix oss-fuzz #62294
1 parent 789867e commit 7925d21

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

Zend/tests/in-de-crement/oss-fuzz-60709_globals.phpt renamed to Zend/tests/in-de-crement/oss-fuzz-60709_globals_unset_after_undef_warning.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
oss-fuzz #60709: Test
2+
oss-fuzz #60709: Unsetting variable after undefined variable warning in ++/--
33
--FILE--
44
<?php
55
set_error_handler(function($_, $m) {
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
--TEST--
2+
oss-fuzz #62294: Unsetting variable after ++/-- on string variable warning
3+
--FILE--
4+
<?php
5+
set_error_handler(function($_, $m) {
6+
echo "$m\n";
7+
unset($GLOBALS['x']);
8+
});
9+
10+
$x=" ";
11+
echo "POST DEC\n";
12+
var_dump($x--);
13+
14+
$x=" ";
15+
echo "PRE DEC\n";
16+
var_dump(--$x);
17+
18+
$x=" ";
19+
echo "POST INC\n";
20+
var_dump($x++);
21+
22+
$x=" ";
23+
echo "PRE INC\n";
24+
var_dump(++$x);
25+
?>
26+
--EXPECT--
27+
POST DEC
28+
Decrement on non-numeric string has no effect and is deprecated
29+
string(1) " "
30+
PRE DEC
31+
Decrement on non-numeric string has no effect and is deprecated
32+
string(1) " "
33+
POST INC
34+
Increment on non-alphanumeric string is deprecated
35+
string(1) " "
36+
PRE INC
37+
Increment on non-alphanumeric string is deprecated
38+
string(1) " "

Zend/zend_operators.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2738,10 +2738,19 @@ ZEND_API zend_result ZEND_FASTCALL decrement_function(zval *op1) /* {{{ */
27382738
ZVAL_DOUBLE(op1, dval - 1);
27392739
break;
27402740
default:
2741+
/* Error handler can unset the variable */
2742+
zend_string *zstr = Z_STR_P(op1);
2743+
GC_TRY_ADDREF(zstr);
27412744
zend_error(E_DEPRECATED, "Decrement on non-numeric string has no effect and is deprecated");
27422745
if (EG(exception)) {
2746+
GC_TRY_DELREF(zstr);
2747+
if (!GC_REFCOUNT(zstr)) {
2748+
efree(zstr);
2749+
}
27432750
return FAILURE;
27442751
}
2752+
zval_ptr_dtor(op1);
2753+
ZVAL_STR(op1, zstr);
27452754
}
27462755
break;
27472756
case IS_NULL: {

0 commit comments

Comments
 (0)