Skip to content

Commit b610dce

Browse files
committed
BIND_STATIC may throw
The evaluation of the initializer may throw. This could be refined by checking whether the initializer is a constant AST. For now just fix the miscompile.
1 parent 12b0f1b commit b610dce

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

ext/opcache/Optimizer/zend_inference.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4552,9 +4552,15 @@ int zend_may_throw_ex(const zend_op *opline, const zend_ssa_op *ssa_op, const ze
45524552
if (t1 & MAY_BE_REF) {
45534553
return 1;
45544554
}
4555-
case ZEND_BIND_STATIC:
45564555
case ZEND_UNSET_VAR:
45574556
return (t1 & (MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_ARRAY_OF_OBJECT|MAY_BE_ARRAY_OF_RESOURCE|MAY_BE_ARRAY_OF_ARRAY));
4557+
case ZEND_BIND_STATIC:
4558+
if (t1 & (MAY_BE_OBJECT|MAY_BE_RESOURCE|MAY_BE_ARRAY_OF_OBJECT|MAY_BE_ARRAY_OF_RESOURCE|MAY_BE_ARRAY_OF_ARRAY)) {
4559+
/* Destructor may throw. */
4560+
return 1;
4561+
}
4562+
/* TODO: May not throw if initializer is not CONSTANT_AST. */
4563+
return 1;
45584564
case ZEND_ASSIGN_DIM:
45594565
if ((opline+1)->op1_type == IS_CV) {
45604566
if (_ssa_op1_info(op_array, ssa, opline+1, ssa_op+1) & MAY_BE_UNDEF) {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Bind static may throw
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
--FILE--
9+
<?php
10+
function test() {
11+
static $N = UNDEFINED;
12+
throw new Exception;
13+
}
14+
try {
15+
test();
16+
} catch (Error $e) {
17+
echo $e->getMessage(), "\n";
18+
}
19+
20+
?>
21+
--EXPECT--
22+
Undefined constant "UNDEFINED"

0 commit comments

Comments
 (0)