Skip to content

Commit 2ae4846

Browse files
committed
Fix OSS-Fuzz #427814452
Pipe compilation uses a temporary znode with QM_ASSIGN to remove references. Assert compilation wants to look at the operand AST and convert it to a string. However the original AST is lost due to the temporary znode. To solve this we either have to handle this specially in pipe compilation [1], or store the AST anyway somehow. Special casing this either way is not worth the complexity in my opinion, especially as it looks like a dynamic call anyway due to the FCC syntax. [1] Prototype (incomplete) at https://gist.github.com/nielsdos/50dc71718639c3af05db84a4dea6eb71 shows this is not worthwhile in my opinion.
1 parent e98879f commit 2ae4846

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
OSS-Fuzz #427814452
3+
--FILE--
4+
<?php
5+
6+
try {
7+
false |> assert(...);
8+
} catch (\AssertionError $e) {
9+
echo $e::class, ": '", $e->getMessage(), "'\n";
10+
}
11+
try {
12+
0 |> "assert"(...);
13+
} catch (\AssertionError $e) {
14+
echo $e::class, ": '", $e->getMessage(), "'\n";
15+
}
16+
try {
17+
false |> ("a"."ssert")(...);
18+
} catch (\AssertionError $e) {
19+
echo $e::class, ": '", $e->getMessage(), "'\n";
20+
}
21+
22+
?>
23+
--EXPECT--
24+
AssertionError: ''
25+
AssertionError: ''
26+
AssertionError: ''

Zend/zend_compile.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4356,7 +4356,10 @@ static void zend_compile_assert(znode *result, zend_ast_list *args, zend_string
43564356
}
43574357
opline->result.num = zend_alloc_cache_slot();
43584358

4359-
if (args->children == 1) {
4359+
/* Skip adding a message on piped assert(...) calls, hence the ZEND_AST_ZNODE check.
4360+
* We don't have access to the original AST anyway, so we would either need to duplicate
4361+
* this logic in pipe compilation or store the AST. Neither seems worth the complexity. */
4362+
if (args->children == 1 && args->child[0]->kind != ZEND_AST_ZNODE) {
43604363
/* add "assert(condition) as assertion message */
43614364
zend_ast *arg = zend_ast_create_zval_from_str(
43624365
zend_ast_export("assert(", args->child[0], ")"));

0 commit comments

Comments
 (0)