Skip to content

Commit 623da03

Browse files
committed
Fix zend_jit_undefined_long_key overwriting dim when dim == result
Fixes oss-fuzz #64727 Closes GH-12900
1 parent ff22409 commit 623da03

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ PHP NEWS
66
. Fix incorrect timeout in built-in web server when using router script and
77
max_input_time. (ilutov)
88

9+
- Opcache:
10+
. Fixed oss-fuzz #64727 (JIT undefined array key warning may overwrite DIM
11+
with NULL when DIM is the same var as result). (ilutov)
12+
913
21 Dec 2023, PHP 8.2.14
1014

1115
- Core:

ext/opcache/jit/zend_jit_vm_helpers.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,14 @@ void ZEND_FASTCALL zend_jit_undefined_long_key(EXECUTE_DATA_D)
205205
zval *result = EX_VAR(opline->result.var);
206206
zval *dim;
207207

208-
ZVAL_NULL(result);
209208
if (opline->op2_type == IS_CONST) {
210209
dim = RT_CONSTANT(opline, opline->op2);
211210
} else {
212211
dim = EX_VAR(opline->op2.var);
213212
}
214213
ZEND_ASSERT(Z_TYPE_P(dim) == IS_LONG);
215214
zend_error(E_WARNING, "Undefined array key " ZEND_LONG_FMT, Z_LVAL_P(dim));
215+
ZVAL_NULL(result);
216216
}
217217

218218
void ZEND_FASTCALL zend_jit_undefined_string_key(EXECUTE_DATA_D)
@@ -222,7 +222,6 @@ void ZEND_FASTCALL zend_jit_undefined_string_key(EXECUTE_DATA_D)
222222
zval *dim;
223223
zend_ulong lval;
224224

225-
ZVAL_NULL(result);
226225
if (opline->op2_type == IS_CONST) {
227226
dim = RT_CONSTANT(opline, opline->op2);
228227
} else {
@@ -234,6 +233,7 @@ void ZEND_FASTCALL zend_jit_undefined_string_key(EXECUTE_DATA_D)
234233
} else {
235234
zend_error(E_WARNING, "Undefined array key \"%s\"", Z_STRVAL_P(dim));
236235
}
236+
ZVAL_NULL(result);
237237
}
238238

239239
ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL zend_jit_profile_helper(ZEND_OPCODE_HANDLER_ARGS)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
oss-fuzz #64727
3+
--INI--
4+
opcache.enable_cli=1
5+
opcache.jit_buffer_size=64M
6+
opcache.jit=function
7+
--EXTENSIONS--
8+
opcache
9+
--FILE--
10+
<?php
11+
function test(){
12+
$a = null;
13+
$b = null;
14+
for($i = 0; $i < 2; $i++){
15+
$a = $a + $b;
16+
var_dump($a);
17+
$a = @[3][$a];
18+
var_dump($a);
19+
}
20+
}
21+
test();
22+
?>
23+
--EXPECT--
24+
int(0)
25+
int(3)
26+
int(3)
27+
NULL

0 commit comments

Comments
 (0)