summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-06-08 14:34:04 +0200
committerNikita Popov <nikita.ppv@gmail.com>2020-06-08 14:34:43 +0200
commit3d4f79d6782299ee8fc0eb14eb858bedef23c5cd (patch)
tree351baed3f98e0b4e15ad85c48fa6b591362ec868
parentb03cafd19c01db57b89727ce77cc89a7d816077c (diff)
downloadphp-git-3d4f79d6782299ee8fc0eb14eb858bedef23c5cd.tar.gz
Don't allow variables as attribute name
Attributes require a static class name... This fixes https://oss-fuzz.com/testcase-detail/6267052359942144.
-rw-r--r--Zend/tests/attributes/018_variable_attribute_name.phpt11
-rw-r--r--Zend/zend_language_parser.y6
2 files changed, 14 insertions, 3 deletions
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--
+<?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
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); }
;