From 27faeedefea5f30db5fb80f81d05e120d1dfae22 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sat, 21 Dec 2024 19:50:27 +0100 Subject: [PATCH] Fix GH-17234: Numeric parent hook call fails with assertion The current code expects the property name to be a string, but it can also be a number via the {} syntax. Handle this consistently to a string by using zval_get_string which will do the type coercion and refcount update (instead of assuming string and doing an explicit string copy). --- Zend/tests/property_hooks/gh17234.phpt | 15 +++++++++++++++ Zend/zend_compile.c | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 Zend/tests/property_hooks/gh17234.phpt diff --git a/Zend/tests/property_hooks/gh17234.phpt b/Zend/tests/property_hooks/gh17234.phpt new file mode 100644 index 0000000000000..18e9c2598f9d5 --- /dev/null +++ b/Zend/tests/property_hooks/gh17234.phpt @@ -0,0 +1,15 @@ +--TEST-- +GH-17234 (Numeric parent hook call fails with assertion) +--FILE-- + +--EXPECTF-- +Fatal error: Must not use parent::$0::get() in a different property ($a) in %s on line %d diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 456c0b8f410b4..70db11c4cc2fc 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -5098,7 +5098,8 @@ static bool zend_compile_parent_property_hook_call(znode *result, zend_ast *ast, zend_error_noreturn(E_COMPILE_ERROR, "Cannot create Closure for parent property hook call"); } - zend_string *property_name = zend_ast_get_str(class_ast->child[1]); + zval *property_hook_name_zv = zend_ast_get_zval(class_ast->child[1]); + zend_string *property_name = zval_get_string(property_hook_name_zv); zend_string *hook_name = zend_ast_get_str(method_ast); zend_property_hook_kind hook_kind = zend_get_property_hook_kind_from_name(hook_name); ZEND_ASSERT(hook_kind != (uint32_t)-1); @@ -5122,7 +5123,6 @@ static bool zend_compile_parent_property_hook_call(znode *result, zend_ast *ast, zend_op *opline = get_next_op(); opline->opcode = ZEND_INIT_PARENT_PROPERTY_HOOK_CALL; opline->op1_type = IS_CONST; - zend_string_copy(property_name); opline->op1.constant = zend_add_literal_string(&property_name); opline->op2.num = hook_kind;