Undef result if undef dim warning promoted to exception

Fixes oss-fuzz #39278.
This commit is contained in:
Nikita Popov 2021-09-28 11:34:44 +02:00
parent f381079398
commit fe1633f010
2 changed files with 40 additions and 0 deletions

View file

@ -684,6 +684,7 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_rw_helper(zend_array *ht, zval *di
goto str_index;
case IS_UNDEF:
if (!zend_jit_undefined_op_helper_write(ht, EG(current_execute_data)->opline->op2.var)) {
undef_result_after_exception();
return NULL;
}
/* break missing intentionally */
@ -768,6 +769,7 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_w_helper(zend_array *ht, zval *dim
goto str_index;
case IS_UNDEF:
if (!zend_jit_undefined_op_helper_write(ht, EG(current_execute_data)->opline->op2.var)) {
undef_result_after_exception();
return NULL;
}
/* break missing intentionally */

View file

@ -0,0 +1,38 @@
--TEST--
Undef to exception for assign dim offset
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.file_update_protection=0
opcache.jit_buffer_size=1M
--FILE--
<?php
set_error_handler(function($_, $m){
throw new Exception($m);
});
function test1() {
$a = [];
$res = $a[$undef] = null;
}
function test2() {
$a = [];
$res = $a[$undef] += 1;
}
function test3() {
$a = [];
$res = isset($a[$undef]);
}
try {
test1();
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
try {
test2();
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
Undefined variable $undef
Undefined variable $undef