From 011e899e6242d8b0229435cc11648f308863dcb5 Mon Sep 17 00:00:00 2001 From: Deus Kane <3399275+qxzkjp@users.noreply.github.com> Date: Sat, 25 Jul 2020 12:02:01 +0100 Subject: [PATCH 1/4] Fixed crash that occurred when a promoted constructor parameter had an annotation This was caused by the attribute AST being used twice, and was fixed by creating a temporary copy of it (and destroying said copy) when neccesary. --- Zend/zend_compile.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index ac9d549756412..b83096c62af69 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -6197,6 +6197,12 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32_t fall zend_op *opline; zend_arg_info *arg_info; + zend_ast_ref *attributes_copy = 0; + + if (visibility && attributes_ast) { + attributes_copy = zend_ast_copy(attributes_ast); + } + if (zend_is_auto_global(name)) { zend_error_noreturn(E_COMPILE_ERROR, "Cannot re-assign auto-global variable %s", ZSTR_VAL(name)); @@ -6350,7 +6356,8 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32_t fall scope, name, &default_value, visibility | ZEND_ACC_PROMOTED, doc_comment, type); if (attributes_ast) { zend_compile_attributes( - &prop->attributes, attributes_ast, 0, ZEND_ATTRIBUTE_TARGET_PROPERTY); + &prop->attributes, GC_AST(attributes_copy), 0, ZEND_ATTRIBUTE_TARGET_PROPERTY); + zend_ast_ref_destroy(attributes_copy); } } } From 9e8cd201efdb1bc1ff946ed54e946868e628d188 Mon Sep 17 00:00:00 2001 From: Deus Kane <3399275+qxzkjp@users.noreply.github.com> Date: Sat, 25 Jul 2020 13:55:07 +0100 Subject: [PATCH 2/4] Added unit test for bug 79897 --- Zend/tests/bug79897/bug79897.phpt | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Zend/tests/bug79897/bug79897.phpt diff --git a/Zend/tests/bug79897/bug79897.phpt b/Zend/tests/bug79897/bug79897.phpt new file mode 100644 index 0000000000000..72024b06fb31c --- /dev/null +++ b/Zend/tests/bug79897/bug79897.phpt @@ -0,0 +1,23 @@ +--TEST-- +bug79897: Promoted constructor params with attribs cause crash +--FILE-- + Date: Wed, 29 Jul 2020 10:16:24 +0100 Subject: [PATCH 3/4] Changed 0 to NULL for pointer value Co-authored-by: Nikita Popov --- Zend/zend_compile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index b83096c62af69..c12412b6ae9aa 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -6197,7 +6197,7 @@ void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast, uint32_t fall zend_op *opline; zend_arg_info *arg_info; - zend_ast_ref *attributes_copy = 0; + zend_ast_ref *attributes_copy = NULL; if (visibility && attributes_ast) { attributes_copy = zend_ast_copy(attributes_ast); From 7b0c1b96e16dae7e23aa05f48256fe3be54b07e7 Mon Sep 17 00:00:00 2001 From: Deus Kane <3399275+qxzkjp@users.noreply.github.com> Date: Wed, 29 Jul 2020 17:13:54 +0100 Subject: [PATCH 4/4] Changed test to make more useful assertions Assertions now check the values that the property and parameter attributes were initialised with --- Zend/tests/{bug79897 => }/bug79897.phpt | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) rename Zend/tests/{bug79897 => }/bug79897.phpt (51%) diff --git a/Zend/tests/bug79897/bug79897.phpt b/Zend/tests/bug79897.phpt similarity index 51% rename from Zend/tests/bug79897/bug79897.phpt rename to Zend/tests/bug79897.phpt index 72024b06fb31c..ed79318c766e4 100644 --- a/Zend/tests/bug79897/bug79897.phpt +++ b/Zend/tests/bug79897.phpt @@ -18,6 +18,15 @@ class A { } } -echo "file compiled successfully"; +var_dump((new ReflectionParameter(['A', '__construct'], 'b'))->getAttributes()[0]->getArguments()); +var_dump((new ReflectionProperty('A', 'b'))->getAttributes()[0]->getArguments()); +?> --EXPECT-- -file compiled successfully +array(1) { + [0]=> + int(12) +} +array(1) { + [0]=> + int(12) +}