Skip to content

Commit 80022c0

Browse files
committed
Fix failed assertion with throwing __toString in binary const expr
Solve this with the same pattern as ZEND_AST_GREATER[_EQUAL]. Fixes OSS-Fuzz #434346548 Closes GH-19291
1 parent be9f1d3 commit 80022c0

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ PHP NEWS
77
(psumbera)
88
. Fixed bug GH-18581 (Coerce numeric string keys from iterators when argument
99
unpacking). (ilutov)
10+
. Fixed OSS-Fuzz #434346548 (Failed assertion with throwing __toString in
11+
binary const expr). (ilutov)
1012

1113
- FTP:
1214
. Fix theoretical issues with hrtime() not being available. (nielsdos)

Zend/tests/oss_fuzz_434346548.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
OSS-Fuzz #434346548: Failed assertion with throwing __toString in binary const expr
3+
--FILE--
4+
<?php
5+
6+
class Foo {
7+
function __toString() {}
8+
}
9+
10+
function test($y = new Foo() < "") {
11+
var_dump();
12+
}
13+
14+
try {
15+
test();
16+
} catch (Error $e) {
17+
echo $e->getMessage(), "\n";
18+
}
19+
20+
?>
21+
--EXPECT--
22+
Foo::__toString(): Return value must be of type string, none returned

Zend/zend_ast.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,10 @@ ZEND_API zend_result ZEND_FASTCALL zend_ast_evaluate_inner(
548548
ret = FAILURE;
549549
} else {
550550
binary_op_type op = get_binary_op(ast->attr);
551-
ret = op(result, &op1, &op2);
551+
op(result, &op1, &op2);
552552
zval_ptr_dtor_nogc(&op1);
553553
zval_ptr_dtor_nogc(&op2);
554+
ret = EG(exception) ? FAILURE : SUCCESS;
554555
}
555556
break;
556557
case ZEND_AST_GREATER:

0 commit comments

Comments
 (0)