From 440676a69a38bf3d847ba9b5627ded7de12e51b9 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Sat, 4 Dec 2021 22:35:57 +0100 Subject: [PATCH] Fix invalid opcode for ??= on $GLOBALS Fixes #81684 --- NEWS | 2 ++ Zend/tests/bug81684.phpt | 11 +++++++++++ Zend/zend_compile.c | 4 +++- 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 Zend/tests/bug81684.phpt diff --git a/NEWS b/NEWS index 64d41569809e..f1ef2bd35efe 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,8 @@ PHP NEWS - Core: . Fixed bug #81216 (Nullsafe operator leaks dynamic property name). (Dmitry) + . Fixed bug #81684 (Using null coalesce assignment with $GLOBALS["x"] produces + opcode error). (ilutov) - MBString: . Fixed bug #81693 (mb_check_encoding(7bit) segfaults). (cmb) diff --git a/Zend/tests/bug81684.phpt b/Zend/tests/bug81684.phpt new file mode 100644 index 000000000000..e47056187a76 --- /dev/null +++ b/Zend/tests/bug81684.phpt @@ -0,0 +1,11 @@ +--TEST-- +Bug #81684: ??= on $GLOBALS produces an invalid opcode +--FILE-- + +--EXPECT-- +string(1) "x" +Done. diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c index 63fb6314c1a7..c136d226e3c2 100644 --- a/Zend/zend_compile.c +++ b/Zend/zend_compile.c @@ -8986,7 +8986,9 @@ static void zend_compile_assign_coalesce(znode *result, zend_ast *ast) /* {{{ */ /* Reproduce some of the zend_compile_assign() opcode fixup logic here. */ opline = &CG(active_op_array)->opcodes[CG(active_op_array)->last-1]; - switch (var_ast->kind) { + /* Treat $GLOBALS['x'] assignment like assignment to variable. */ + zend_ast_kind kind = is_global_var_fetch(var_ast) ? ZEND_AST_VAR : var_ast->kind; + switch (kind) { case ZEND_AST_VAR: zend_emit_op_tmp(&assign_node, ZEND_ASSIGN, &var_node_w, &default_node); break;