Skip to content

Commit 4ba5699

Browse files
committed
Fix invalid returned opcode for memoized expressions
Closes GH-12345
1 parent f7cef9a commit 4ba5699

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ PHP NEWS
44

55
- Core:
66
. Fixed bug #80092 (ZTS + preload = segfault on shutdown). (nielsdos)
7+
. Fixed buffer underflow when compiling memoized expression. (ilutov)
78

89
- CType:
910
. Fixed bug GH-11997 (ctype_alnum 5 times slower in PHP 8.1 or greater).

Zend/tests/assign_coalesce_009.phpt

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
--TEST--
2+
Invalid opcode returned from zend_compile_var_inner() for memoized expression
3+
--FILE--
4+
<?php
5+
strlen("foo")[0] ??= 123;
6+
?>
7+
--EXPECTF--
8+
Fatal error: Cannot use result of built-in function in write context in %s on line %d

Zend/zend_compile.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -10616,7 +10616,8 @@ static zend_op *zend_compile_var_inner(znode *result, zend_ast *ast, uint32_t ty
1061610616
case ZEND_AST_NULLSAFE_METHOD_CALL:
1061710617
case ZEND_AST_STATIC_CALL:
1061810618
zend_compile_memoized_expr(result, ast);
10619-
return &CG(active_op_array)->opcodes[CG(active_op_array)->last - 1];
10619+
/* This might not actually produce an opcode, e.g. for expressions evaluated at comptime. */
10620+
return NULL;
1062010621
}
1062110622
}
1062210623

0 commit comments

Comments
 (0)