]> granicus.if.org Git - php/commitdiff
Don't allow variables as attribute name
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 8 Jun 2020 12:34:04 +0000 (14:34 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 8 Jun 2020 12:34:43 +0000 (14:34 +0200)
Attributes require a static class name...

This fixes https://oss-fuzz.com/testcase-detail/6267052359942144.

Zend/tests/attributes/018_variable_attribute_name.phpt [new file with mode: 0644]
Zend/zend_language_parser.y

diff --git a/Zend/tests/attributes/018_variable_attribute_name.phpt b/Zend/tests/attributes/018_variable_attribute_name.phpt
new file mode 100644 (file)
index 0000000..64fb69a
--- /dev/null
@@ -0,0 +1,11 @@
+--TEST--
+Attribute name cannot be a variable
+--FILE--
+<?php
+
+<<$x>>
+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
index 80a57514b9fefe4ce1bbfdd93ed989f5cb2e6846..b1b9aff1554008a519414cb2c9545e3938cf1606 100644 (file)
@@ -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); }
 ;