Skip to content

Commit

Permalink
Fix assert with attribute + first-class callable in assert
Browse files Browse the repository at this point in the history
This is going to result in a compile-time error, but AST printing
is invoked first and should handle it gracefully. Handle it by
falling back to more generic printing code.

Fixes oss-fuzz #36264.
  • Loading branch information
nikic committed Jul 19, 2021
1 parent e120d52 commit b6dcab2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
11 changes: 11 additions & 0 deletions Zend/tests/first_class_callable_assert2.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--TEST--
Foo(...) in attribute in assert
--FILE--
<?php
assert(function() {
#[Foo(...)]
class Test {}
});
?>
--EXPECTF--
Fatal error: Cannot create Closure as attribute argument in %s on line %d
13 changes: 2 additions & 11 deletions Zend/zend_ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1480,9 +1480,7 @@ static ZEND_COLD void zend_ast_export_class_no_header(smart_str *str, zend_ast_d

static ZEND_COLD void zend_ast_export_attribute_group(smart_str *str, zend_ast *ast, int indent) {
zend_ast_list *list = zend_ast_get_list(ast);
uint32_t i, j;

for (i = 0; i < list->children; i++) {
for (uint32_t i = 0; i < list->children; i++) {
zend_ast *attr = list->child[i];

if (i) {
Expand All @@ -1491,15 +1489,8 @@ static ZEND_COLD void zend_ast_export_attribute_group(smart_str *str, zend_ast *
zend_ast_export_ns_name(str, attr->child[0], 0, indent);

if (attr->child[1]) {
zend_ast_list *args = zend_ast_get_list(attr->child[1]);

smart_str_appendc(str, '(');
for (j = 0; j < args->children; j++) {
if (j) {
smart_str_appends(str, ", ");
}
zend_ast_export_ex(str, args->child[j], 0, indent);
}
zend_ast_export_ex(str, attr->child[1], 0, indent);
smart_str_appendc(str, ')');
}
}
Expand Down

0 comments on commit b6dcab2

Please sign in to comment.