Skip to content

Commit 6e1fe96

Browse files
committed
JIT: Fix uninitialized result of ASSIGN_DIM[_OP] after clobbering array by user error handler
Fixes oss-fuzz #41208
1 parent 86430e8 commit 6e1fe96

File tree

2 files changed

+44
-6
lines changed

2 files changed

+44
-6
lines changed

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,8 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_rw_helper(zend_array *ht, zval *di
673673
zend_ulong hval;
674674
zend_string *offset_key;
675675
zval *retval;
676+
zend_execute_data *execute_data;
677+
const zend_op *opline;
676678

677679
if (Z_TYPE_P(dim) == IS_REFERENCE) {
678680
dim = Z_REFVAL_P(dim);
@@ -686,9 +688,15 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_rw_helper(zend_array *ht, zval *di
686688
offset_key = Z_STR_P(dim);
687689
goto str_index;
688690
case IS_UNDEF:
689-
if (!zend_jit_undefined_op_helper_write(ht, EG(current_execute_data)->opline->op2.var)) {
690-
if (EG(exception)) {
691-
undef_result_after_exception();
691+
execute_data = EG(current_execute_data);
692+
opline = EX(opline);
693+
if (!zend_jit_undefined_op_helper_write(ht, opline->op2.var)) {
694+
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
695+
if (EG(exception)) {
696+
ZVAL_UNDEF(EX_VAR(opline->result.var));
697+
} else {
698+
ZVAL_NULL(EX_VAR(opline->result.var));
699+
}
692700
}
693701
return NULL;
694702
}
@@ -760,6 +768,8 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_w_helper(zend_array *ht, zval *dim
760768
zend_ulong hval;
761769
zend_string *offset_key;
762770
zval *retval;
771+
zend_execute_data *execute_data;
772+
const zend_op *opline;
763773

764774
if (Z_TYPE_P(dim) == IS_REFERENCE) {
765775
dim = Z_REFVAL_P(dim);
@@ -773,9 +783,15 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_w_helper(zend_array *ht, zval *dim
773783
offset_key = Z_STR_P(dim);
774784
goto str_index;
775785
case IS_UNDEF:
776-
if (!zend_jit_undefined_op_helper_write(ht, EG(current_execute_data)->opline->op2.var)) {
777-
if (EG(exception)) {
778-
undef_result_after_exception();
786+
execute_data = EG(current_execute_data);
787+
opline = EX(opline);
788+
if (!zend_jit_undefined_op_helper_write(ht, opline->op2.var)) {
789+
if (opline->result_type & (IS_VAR | IS_TMP_VAR)) {
790+
if (EG(exception)) {
791+
ZVAL_UNDEF(EX_VAR(opline->result.var));
792+
} else {
793+
ZVAL_NULL(EX_VAR(opline->result.var));
794+
}
779795
}
780796
return NULL;
781797
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
JIT ASSIGN_DIM: 005
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+
set_error_handler(function ($code, $msg) {
11+
echo "Error: $msg\n";
12+
$GLOBALS['a'] = null;
13+
});
14+
15+
$a[$c] =
16+
$a[$c] = 'x' ;
17+
var_dump($a);
18+
?>
19+
--EXPECT--
20+
Error: Undefined variable $c
21+
Error: Undefined variable $c
22+
NULL

0 commit comments

Comments
 (0)