]> granicus.if.org Git - php/commitdiff
Fix leak with nullsafe operator with constant LHS
authorNikita Popov <nikita.ppv@gmail.com>
Wed, 29 Jul 2020 13:51:47 +0000 (15:51 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 29 Jul 2020 13:51:47 +0000 (15:51 +0200)
Followup to 5303bcdd32e8171399c2c60bf431e5304a66c39a. We need to
perform the addref after emitting the opline, because that might
intern the string.

Fixes oss-fuzz #24479.

Zend/tests/nullsafe_operator/029.phpt
Zend/zend_compile.c

index 2aee652140b3a0ace14692d0747b00b049832dac..92a17ef7c012b9661f2d58358d12e8fe533ccbf1 100644 (file)
@@ -3,6 +3,9 @@ Refcount of constant LHS with nullsafe operator
 --FILE--
 <?php
 ['']?->a;
+__DIR__?->a;
 ?>
 --EXPECTF--
 Warning: Attempt to read property "a" on array in %s on line %d
+
+Warning: Attempt to read property "a" on string in %s on line %d
index ac9d54975641291bafd76cbb47c7bc5a61894d7f..a2ec221a01793611bc4e3ed6c8560a70651634d6 100644 (file)
@@ -2308,10 +2308,10 @@ static void zend_short_circuiting_commit(uint32_t checkpoint, znode *result, zen
 static void zend_emit_jmp_null(znode *obj_node)
 {
        uint32_t jmp_null_opnum = get_next_op_number();
-       if (obj_node->op_type == IS_CONST) {
-               Z_TRY_ADDREF(obj_node->u.constant);
+       zend_op *opline = zend_emit_op(NULL, ZEND_JMP_NULL, obj_node, NULL);
+       if (opline->op1_type == IS_CONST) {
+               Z_TRY_ADDREF_P(CT_CONSTANT(opline->op1));
        }
-       zend_emit_op(NULL, ZEND_JMP_NULL, obj_node, NULL);
        zend_stack_push(&CG(short_circuiting_opnums), &jmp_null_opnum);
 }