Skip to content

Commit 56c4ddf

Browse files
committed
Fix phpGH-18899: JIT function crash when emitting undefined variable warning and opline is not set yet
The crash happens because EX(opline) is attempted to be accessed but it's not set yet. Closes phpGH-18904.
1 parent ee2c0d7 commit 56c4ddf

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ PHP NEWS
2424
- Opcache:
2525
. Fixed bug GH-18639 (Internal class aliases can break preloading + JIT).
2626
(nielsdos)
27+
. Fixed bug GH-18899 (JIT function crash when emitting undefined variable
28+
warning and opline is not set yet). (nielsdos)
2729

2830
- Standard:
2931
. Fix misleading errors in printf(). (nielsdos)

ext/opcache/jit/zend_jit_ir.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5981,6 +5981,7 @@ static int zend_jit_long_math_helper(zend_jit_ctx *jit,
59815981
ir_IF_FALSE_cold(if_def);
59825982

59835983
// zend_error_unchecked(E_WARNING, "Undefined variable $%S", CV_DEF_OF(EX_VAR_TO_NUM(opline->op1.var)));
5984+
jit_SET_EX_OPLINE(jit, opline);
59845985
ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_undefined_op_helper), ir_CONST_U32(opline->op1.var));
59855986

59865987
ref2 = jit_EG(uninitialized_zval);
@@ -5997,6 +5998,7 @@ static int zend_jit_long_math_helper(zend_jit_ctx *jit,
59975998
ir_IF_FALSE_cold(if_def);
59985999

59996000
// zend_error_unchecked(E_WARNING, "Undefined variable $%S", CV_DEF_OF(EX_VAR_TO_NUM(opline->op2.var)));
6001+
jit_SET_EX_OPLINE(jit, opline);
60006002
ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_undefined_op_helper), ir_CONST_U32(opline->op2.var));
60016003

60026004
ref2 = jit_EG(uninitialized_zval);

ext/opcache/tests/jit/gh18899.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
GH-18899 (JIT function crash when emitting undefined variable warning and opline is not set yet)
3+
--EXTENSIONS--
4+
opcache
5+
--INI--
6+
opcache.enable=1
7+
opcache.enable_cli=1
8+
opcache.jit=1205
9+
opcache.jit_buffer_size=8M
10+
--FILE--
11+
<?php
12+
function ptr2str()
13+
{
14+
for ($i=0; $i<8; $i++) {
15+
$ptr >>= 8;
16+
}
17+
}
18+
str_repeat("A",232).ptr2str();
19+
?>
20+
--EXPECTF--
21+
Warning: Undefined variable $ptr in %s on line %d

0 commit comments

Comments
 (0)