Skip to content

Commit 6259eff

Browse files
committed
Handle dim_w undefined variable notice in JIT as well
1 parent 0e6ec97 commit 6259eff

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,24 @@ static int ZEND_FASTCALL zend_jit_undefined_op_helper(uint32_t var)
287287
return EG(exception) == NULL;
288288
}
289289

290+
static int ZEND_FASTCALL zend_jit_undefined_op_helper_write(HashTable *ht, uint32_t var)
291+
{
292+
const zend_execute_data *execute_data = EG(current_execute_data);
293+
zend_string *cv = EX(func)->op_array.vars[EX_VAR_TO_NUM(var)];
294+
295+
/* The array may be destroyed while throwing the notice.
296+
* Temporarily increase the refcount to detect this situation. */
297+
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE)) {
298+
GC_ADDREF(ht);
299+
}
300+
zend_error(E_WARNING, "Undefined variable $%s", ZSTR_VAL(cv));
301+
if (!(GC_FLAGS(ht) & IS_ARRAY_IMMUTABLE) && !GC_DELREF(ht)) {
302+
zend_array_destroy(ht);
303+
return 0;
304+
}
305+
return EG(exception) == NULL;
306+
}
307+
290308
static void ZEND_FASTCALL zend_jit_fetch_dim_r_helper(zend_array *ht, zval *dim, zval *result)
291309
{
292310
zend_long hval;
@@ -513,7 +531,9 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_rw_helper(zend_array *ht, zval *di
513531
offset_key = Z_STR_P(dim);
514532
goto str_index;
515533
case IS_UNDEF:
516-
zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var);
534+
if (!zend_jit_undefined_op_helper_write(ht, EG(current_execute_data)->opline->op2.var)) {
535+
return NULL;
536+
}
517537
/* break missing intentionally */
518538
case IS_NULL:
519539
offset_key = ZSTR_EMPTY_ALLOC();
@@ -588,7 +608,9 @@ static zval* ZEND_FASTCALL zend_jit_fetch_dim_w_helper(zend_array *ht, zval *dim
588608
offset_key = Z_STR_P(dim);
589609
goto str_index;
590610
case IS_UNDEF:
591-
zend_jit_undefined_op_helper(EG(current_execute_data)->opline->op2.var);
611+
if (!zend_jit_undefined_op_helper_write(ht, EG(current_execute_data)->opline->op2.var)) {
612+
return NULL;
613+
}
592614
/* break missing intentionally */
593615
case IS_NULL:
594616
offset_key = ZSTR_EMPTY_ALLOC();

0 commit comments

Comments
 (0)