Skip to content

Commit 0b614a6

Browse files
committed
Fixed oss-fuzz #62294: Unsetting variable after ++/-- on string variable warning
Closes GH-12202
1 parent 673babe commit 0b614a6

4 files changed

+51
-7
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ PHP NEWS
55
- Core:
66
. Fixed bug GH-12189 (#[Override] attribute in trait does not check for
77
parent class implementations). (timwolla)
8+
. Fixed OSS Fuzz #62294 (Unsetting variable after ++/-- on string variable
9+
warning). (Girgias)
810

911
- Filter:
1012
. Fix explicit FILTER_REQUIRE_SCALAR with FILTER_CALLBACK (ilutov)

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

+1-1
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) {
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

+10-6
Original file line numberDiff line numberDiff line change
@@ -2528,13 +2528,10 @@ static bool ZEND_FASTCALL increment_string(zval *str) /* {{{ */
25282528

25292529
if (UNEXPECTED(!zend_string_only_has_ascii_alphanumeric(Z_STR_P(str)))) {
25302530
zend_string *zstr = Z_STR_P(str);
2531-
GC_TRY_ADDREF(zstr);
2531+
zend_string_addref(zstr);
25322532
zend_error(E_DEPRECATED, "Increment on non-alphanumeric string is deprecated");
25332533
if (EG(exception)) {
2534-
GC_TRY_DELREF(zstr);
2535-
if (!GC_REFCOUNT(zstr)) {
2536-
efree(zstr);
2537-
}
2534+
zend_string_release(zstr);
25382535
return false;
25392536
}
25402537
zval_ptr_dtor(str);
@@ -2737,11 +2734,18 @@ ZEND_API zend_result ZEND_FASTCALL decrement_function(zval *op1) /* {{{ */
27372734
zval_ptr_dtor_str(op1);
27382735
ZVAL_DOUBLE(op1, dval - 1);
27392736
break;
2740-
default:
2737+
default: {
2738+
/* Error handler can unset the variable */
2739+
zend_string *zstr = Z_STR_P(op1);
2740+
zend_string_addref(zstr);
27412741
zend_error(E_DEPRECATED, "Decrement on non-numeric string has no effect and is deprecated");
27422742
if (EG(exception)) {
2743+
zend_string_release(zstr);
27432744
return FAILURE;
27442745
}
2746+
zval_ptr_dtor(op1);
2747+
ZVAL_STR(op1, zstr);
2748+
}
27452749
}
27462750
break;
27472751
case IS_NULL: {

0 commit comments

Comments
 (0)