Skip to content

Commit 78c7289

Browse files
committed
Fixed incorrect DCE for FREE
Fixes oss-fuzz #44863
1 parent cd1c6f0 commit 78c7289

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

ext/opcache/Optimizer/dce.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,9 @@ static zend_bool dce_instr(context *ctx, zend_op *opline, zend_ssa_op *ssa_op) {
391391
}
392392

393393
/* We mark FREEs as dead, but they're only really dead if the destroyed var is dead */
394-
if (opline->opcode == ZEND_FREE && may_be_refcounted(ssa->var_info[ssa_op->op1_use].type)
394+
if (opline->opcode == ZEND_FREE
395+
&& ((ssa->var_info[ssa_op->op1_use].type & (MAY_BE_REF|MAY_BE_ANY|MAY_BE_UNDEF)) == 0
396+
|| may_be_refcounted(ssa->var_info[ssa_op->op1_use].type))
395397
&& !is_var_dead(ctx, ssa_op->op1_use)) {
396398
return 0;
397399
}

ext/opcache/tests/opt/dce_013.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Incorrect DCE of FREE
3+
--FILE--
4+
<?php
5+
function foo() {
6+
$a = $r[] = $r = []&$y;
7+
list(&$y)=$a;
8+
}
9+
?>
10+
DONE
11+
--EXPECT--
12+
DONE

0 commit comments

Comments
 (0)