From 3d4f79d6782299ee8fc0eb14eb858bedef23c5cd Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 8 Jun 2020 14:34:04 +0200 Subject: [PATCH] Don't allow variables as attribute name Attributes require a static class name... This fixes https://oss-fuzz.com/testcase-detail/6267052359942144. --- .../tests/attributes/018_variable_attribute_name.phpt | 11 +++++++++++ Zend/zend_language_parser.y | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 Zend/tests/attributes/018_variable_attribute_name.phpt diff --git a/Zend/tests/attributes/018_variable_attribute_name.phpt b/Zend/tests/attributes/018_variable_attribute_name.phpt new file mode 100644 index 0000000000..64fb69a4e0 --- /dev/null +++ b/Zend/tests/attributes/018_variable_attribute_name.phpt @@ -0,0 +1,11 @@ +--TEST-- +Attribute name cannot be a variable +--FILE-- +> +class A {} + +?> +--EXPECTF-- +Parse error: syntax error, unexpected '$x' (T_VARIABLE), expecting identifier (T_STRING) or static (T_STATIC) or namespace (T_NAMESPACE) or \\ (T_NS_SEPARATOR) in %s on line %d diff --git a/Zend/zend_language_parser.y b/Zend/zend_language_parser.y index 80a57514b9..b1b9aff155 100644 --- a/Zend/zend_language_parser.y +++ b/Zend/zend_language_parser.y @@ -325,11 +325,11 @@ attribute_arguments: ; attribute_decl: - class_name_reference + class_name { $$ = zend_ast_create(ZEND_AST_ATTRIBUTE, $1, NULL); } - | class_name_reference '(' ')' + | class_name '(' ')' { $$ = zend_ast_create(ZEND_AST_ATTRIBUTE, $1, NULL); } - | class_name_reference '(' attribute_arguments ')' + | class_name '(' attribute_arguments ')' { $$ = zend_ast_create(ZEND_AST_ATTRIBUTE, $1, $3); } ; -- 2.50.1