Skip to content

Commit 23e4e3b

Browse files
committed
Fixed compilation of match with undefined input
Fixes oss-fuzz #63542
1 parent f9a9008 commit 23e4e3b

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

ext/opcache/jit/zend_jit_ir.c

+7-3
Original file line numberDiff line numberDiff line change
@@ -15549,9 +15549,13 @@ static int zend_jit_switch(zend_jit_ctx *jit, const zend_op *opline, const zend_
1554915549
ir_MERGE_list(continue_list);
1555015550
} else {
1555115551
if (default_input_list) {
15552-
ZEND_ASSERT(jit->ctx.ir_base[ref].op == IR_SWITCH);
15553-
ZEND_ASSERT(jit->ctx.ir_base[ref].op3 == IR_UNUSED);
15554-
jit->ctx.ir_base[ref].op3 = default_input_list;
15552+
if (jit->ctx.ir_base[ref].op == IR_SWITCH) {
15553+
ZEND_ASSERT(jit->ctx.ir_base[ref].op3 == IR_UNUSED);
15554+
jit->ctx.ir_base[ref].op3 = default_input_list;
15555+
} else {
15556+
ir_MERGE_list(default_input_list);
15557+
_zend_jit_add_predecessor_ref(jit, default_b, jit->b, ir_END());
15558+
}
1555515559
}
1555615560
jit->b = -1;
1555715561
}

ext/opcache/tests/jit/match_001.phpt

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Match with undefined input
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 foo() {
11+
return match($y){1,6=>0};
12+
}
13+
foo();
14+
?>
15+
--EXPECTF--
16+
Warning: Undefined variable $y in %smatch_001.php on line 3
17+
18+
Fatal error: Uncaught UnhandledMatchError: Unhandled match case NULL in %smatch_001.php:3
19+
Stack trace:
20+
#0 %smatch_001.php(5): foo()
21+
#1 {main}
22+
thrown in %smatch_001.php on line 3

0 commit comments

Comments
 (0)