Skip to content

Commit

Permalink
Check exception after QM_ASSIGN of undef var
Browse files Browse the repository at this point in the history
While most other exceptions aren't possible when QM_ASSIGN is used
instead of ASSIGN, we still have to watch out for an undef var
notice being promoted to an exception.
  • Loading branch information
nikic committed Sep 28, 2021
1 parent 17d6efc commit f381079
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ext/opcache/jit/zend_jit_x86.dasc
Original file line number Diff line number Diff line change
Expand Up @@ -8790,6 +8790,9 @@ static int zend_jit_qm_assign(dasm_State **Dst, const zend_op *opline, uint32_t
if (!zend_jit_store_var_if_necessary(Dst, opline->result.var, res_addr, res_info)) {
return 0;
}
if (op1_info & MAY_BE_UNDEF) {
zend_jit_check_exception(Dst);
}
return 1;
}

Expand Down
22 changes: 22 additions & 0 deletions ext/opcache/tests/jit/qm_assign_undef_exception.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--TEST--
QM_ASSIGN of undef var may throw exception
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.file_update_protection=0
opcache.jit_buffer_size=1M
--FILE--
<?php
set_error_handler(function($_, $m) { throw new Exception($m); });
function test() {
$a = $b;
X;
}
try {
test();
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
Undefined variable $b

0 comments on commit f381079

Please sign in to comment.