Skip to content

Commit

Permalink
Fix AST print of first class callable in anon class expr
Browse files Browse the repository at this point in the history
This will cause a compile error later, but the expression is
printed first.

Fixes oss-fuzz #37473.
  • Loading branch information
nikic committed Aug 26, 2021
1 parent 0798443 commit b964d00
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions Zend/tests/first_class_callable_assert3.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
new class(...) in assert
--FILE--
<?php

assert(new class(...) {});

?>
--EXPECTF--
Fatal error: Cannot create Closure for new expression in %s on line %d
3 changes: 2 additions & 1 deletion Zend/zend_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -2036,7 +2036,8 @@ static ZEND_COLD void zend_ast_export_ex(smart_str *str, zend_ast *ast, int prio
zend_ast_export_attributes(str, decl->child[3], indent, 0);
}
smart_str_appends(str, "class");
if (zend_ast_get_list(ast->child[1])->children) {
if (!zend_ast_is_list(ast->child[1])
|| zend_ast_get_list(ast->child[1])->children) {
smart_str_appendc(str, '(');
zend_ast_export_ex(str, ast->child[1], 0, indent);
smart_str_appendc(str, ')');
Expand Down

0 comments on commit b964d00

Please sign in to comment.