Skip to content

Commit b6dcab2

Browse files
committed
Fix assert with attribute + first-class callable in assert
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.
1 parent e120d52 commit b6dcab2

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
Foo(...) in attribute in assert
3+
--FILE--
4+
<?php
5+
assert(function() {
6+
#[Foo(...)]
7+
class Test {}
8+
});
9+
?>
10+
--EXPECTF--
11+
Fatal error: Cannot create Closure as attribute argument in %s on line %d

Zend/zend_ast.c

+2-11
Original file line numberDiff line numberDiff line change
@@ -1480,9 +1480,7 @@ static ZEND_COLD void zend_ast_export_class_no_header(smart_str *str, zend_ast_d
14801480

14811481
static ZEND_COLD void zend_ast_export_attribute_group(smart_str *str, zend_ast *ast, int indent) {
14821482
zend_ast_list *list = zend_ast_get_list(ast);
1483-
uint32_t i, j;
1484-
1485-
for (i = 0; i < list->children; i++) {
1483+
for (uint32_t i = 0; i < list->children; i++) {
14861484
zend_ast *attr = list->child[i];
14871485

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

14931491
if (attr->child[1]) {
1494-
zend_ast_list *args = zend_ast_get_list(attr->child[1]);
1495-
14961492
smart_str_appendc(str, '(');
1497-
for (j = 0; j < args->children; j++) {
1498-
if (j) {
1499-
smart_str_appends(str, ", ");
1500-
}
1501-
zend_ast_export_ex(str, args->child[j], 0, indent);
1502-
}
1493+
zend_ast_export_ex(str, attr->child[1], 0, indent);
15031494
smart_str_appendc(str, ')');
15041495
}
15051496
}

0 commit comments

Comments
 (0)