Skip to content

Commit af01255

Browse files
committed
Fix constant propagation for JMP_NULL
We must not destroy the source when propagating to op1 of JMP_NULL because the same TMP_VAR will be used again in the false block. Fixes oss-fuzz #60736
1 parent 6e3c520 commit af01255

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

Zend/Optimizer/block_pass.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,14 @@ static void zend_optimize_block(zend_basic_block *block, zend_op_array *op_array
173173
&& opline->opcode != ZEND_SWITCH_STRING
174174
&& opline->opcode != ZEND_MATCH
175175
&& zend_optimizer_update_op1_const(op_array, opline, &c)) {
176-
VAR_SOURCE(op1) = NULL;
177-
literal_dtor(&ZEND_OP1_LITERAL(src));
178-
MAKE_NOP(src);
179-
++(*opt_count);
176+
/* Don't remove QM_ASSIGN for JMP_NULL because the same TMP_VAR is used in a
177+
* later instruction and will be removed then. */
178+
if (opline->opcode != ZEND_JMP_NULL) {
179+
VAR_SOURCE(op1) = NULL;
180+
literal_dtor(&ZEND_OP1_LITERAL(src));
181+
MAKE_NOP(src);
182+
++(*opt_count);
183+
}
180184
} else {
181185
zval_ptr_dtor_nogc(&c);
182186
}

Zend/tests/oss_fuzz_60736.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--TEST--
2+
oss-fuzz #60736: Bad constant propagation in JMP_NULL
3+
--FILE--
4+
<?php
5+
(1?4:y)?->y;
6+
?>
7+
--EXPECTF--
8+
Warning: Attempt to read property "y" on int in %s on line %d

0 commit comments

Comments
 (0)