Skip to content

Commit 5303bcd

Browse files
committed
Fix use-after-free when nullsafe used with constant LHS
Fixes oss-fuzz #24436.
1 parent 2dbb4ec commit 5303bcd

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Zend/tests/nullsafe_operator/029.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--TEST--
2+
Refcount of constant LHS with nullsafe operator
3+
--FILE--
4+
<?php
5+
['']?->a;
6+
?>
7+
--EXPECTF--
8+
Warning: Attempt to read property "a" on array in %s on line %d

Zend/zend_compile.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,6 +2308,9 @@ static void zend_short_circuiting_commit(uint32_t checkpoint, znode *result, zen
23082308
static void zend_emit_jmp_null(znode *obj_node)
23092309
{
23102310
uint32_t jmp_null_opnum = get_next_op_number();
2311+
if (obj_node->op_type == IS_CONST) {
2312+
Z_TRY_ADDREF(obj_node->u.constant);
2313+
}
23112314
zend_emit_op(NULL, ZEND_JMP_NULL, obj_node, NULL);
23122315
zend_stack_push(&CG(short_circuiting_opnums), &jmp_null_opnum);
23132316
}

0 commit comments

Comments
 (0)