Skip to content

Commit ee7eecf

Browse files
committed
Fix leak with nullsafe operator with constant LHS
Followup to 5303bcd. We need to perform the addref after emitting the opline, because that might intern the string. Fixes oss-fuzz #24479.
1 parent c206c74 commit ee7eecf

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Zend/tests/nullsafe_operator/029.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ Refcount of constant LHS with nullsafe operator
33
--FILE--
44
<?php
55
['']?->a;
6+
__DIR__?->a;
67
?>
78
--EXPECTF--
89
Warning: Attempt to read property "a" on array in %s on line %d
10+
11+
Warning: Attempt to read property "a" on string in %s on line %d

Zend/zend_compile.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2308,10 +2308,10 @@ 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);
2311+
zend_op *opline = zend_emit_op(NULL, ZEND_JMP_NULL, obj_node, NULL);
2312+
if (opline->op1_type == IS_CONST) {
2313+
Z_TRY_ADDREF_P(CT_CONSTANT(opline->op1));
23132314
}
2314-
zend_emit_op(NULL, ZEND_JMP_NULL, obj_node, NULL);
23152315
zend_stack_push(&CG(short_circuiting_opnums), &jmp_null_opnum);
23162316
}
23172317

0 commit comments

Comments
 (0)