Skip to content

Commit dbde68f

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fixed bug #81216 (Nullsafe operator leaks dynamic property name)
2 parents 97f78b3 + 307e476 commit dbde68f

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

Zend/tests/bug81216.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
Bug #81216: Nullsafe operator leaks dynamic property name
3+
--FILE--
4+
<?php
5+
$str = "foo";
6+
null?->{$str . "bar"};
7+
?>
8+
DONE
9+
--EXPECT--
10+
DONE

Zend/zend_compile.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,11 +2178,9 @@ static zend_op *zend_delayed_compile_end(uint32_t offset) /* {{{ */
21782178

21792179
ZEND_ASSERT(count >= offset);
21802180
for (i = offset; i < count; ++i) {
2181-
opline = get_next_op();
2182-
memcpy(opline, &oplines[i], sizeof(zend_op));
2183-
if (opline->opcode == ZEND_JMP_NULL) {
2184-
uint32_t opnum = get_next_op_number() - 1;
2185-
zend_stack_push(&CG(short_circuiting_opnums), &opnum);
2181+
if (oplines[i].opcode != ZEND_NOP) {
2182+
opline = get_next_op();
2183+
memcpy(opline, &oplines[i], sizeof(zend_op));
21862184
}
21872185
}
21882186

@@ -2826,11 +2824,18 @@ static zend_op *zend_delayed_compile_prop(znode *result, zend_ast *ast, uint32_t
28262824

28272825
zend_separate_if_call_and_write(&obj_node, obj_ast, type);
28282826
if (nullsafe) {
2829-
/* We will push to the short_circuiting_opnums stack in zend_delayed_compile_end(). */
2830-
opline = zend_delayed_emit_op(NULL, ZEND_JMP_NULL, &obj_node, NULL);
2831-
if (opline->op1_type == IS_CONST) {
2832-
Z_TRY_ADDREF_P(CT_CONSTANT(opline->op1));
2827+
/* Flush delayed oplines */
2828+
zend_op *opline = NULL, *oplines = zend_stack_base(&CG(delayed_oplines_stack));
2829+
uint32_t i, count = zend_stack_count(&CG(delayed_oplines_stack));
2830+
2831+
for (i = 0; i < count; ++i) {
2832+
if (oplines[i].opcode != ZEND_NOP) {
2833+
opline = get_next_op();
2834+
memcpy(opline, &oplines[i], sizeof(zend_op));
2835+
oplines[i].opcode = ZEND_NOP;
2836+
}
28332837
}
2838+
zend_emit_jmp_null(&obj_node);
28342839
}
28352840
}
28362841

0 commit comments

Comments
 (0)