Skip to content

Commit

Permalink
Don't jit FE_RESET_R with undef operand
Browse files Browse the repository at this point in the history
The implementation currently assumes that the operand is always
an array, but this did not account for a possibly undef operand.
  • Loading branch information
nikic committed Sep 17, 2021
1 parent e250ce6 commit d46b102
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ext/opcache/jit/zend_jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -3282,7 +3282,7 @@ static int zend_jit(const zend_op_array *op_array, zend_ssa *ssa, const zend_op
goto done;
case ZEND_FE_RESET_R:
op1_info = OP1_INFO();
if ((op1_info & (MAY_BE_ANY|MAY_BE_REF)) != MAY_BE_ARRAY) {
if ((op1_info & (MAY_BE_ANY|MAY_BE_REF|MAY_BE_UNDEF)) != MAY_BE_ARRAY) {
break;
}
if (!zend_jit_fe_reset(&dasm_state, opline, op1_info)) {
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/jit/zend_jit_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -5527,7 +5527,7 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
case ZEND_FE_RESET_R:
op1_info = OP1_INFO();
CHECK_OP1_TRACE_TYPE();
if ((op1_info & (MAY_BE_ANY|MAY_BE_REF)) != MAY_BE_ARRAY) {
if ((op1_info & (MAY_BE_ANY|MAY_BE_REF|MAY_BE_UNDEF)) != MAY_BE_ARRAY) {
break;
}
if (!zend_jit_fe_reset(&dasm_state, opline, op1_info)) {
Expand Down
21 changes: 21 additions & 0 deletions ext/opcache/tests/jit/fe_reset_undef.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
--TEST--
FE_RESET with potentially undef operand
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.file_update_protection=0
opcache.jit_buffer_size=1M
--FILE--
<?php
function test($c) {
if ($c) {
$a[] = null;
}
foreach ($a as $k) {}
}
test(false);
?>
--EXPECTF--
Warning: Undefined variable $a in %s on line %d

Warning: foreach() argument must be of type array|object, null given in %s on line %d

0 comments on commit d46b102

Please sign in to comment.