Skip to content

Commit dbbcbcb

Browse files
committed
Merge branch 'PHP-8.2'
* PHP-8.2: Fix use-of-uninitialized-value with ??= on assert
2 parents 80873d2 + ac3ff5b commit dbbcbcb

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ PHP NEWS
88

99
- Core:
1010
. Fixed line number of JMP instruction over else block. (ilutov)
11+
. Fixed use-of-uninitialized-value with ??= on assert. (ilutov)
1112

1213
06 Jul 2023, PHP 8.3.0alpha3
1314

Zend/tests/gh11580.phpt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
--TEST--
2+
GH-11580: assert() with ??= operator can lead to use-of-uninitialized-value
3+
--INI--
4+
zend.assertions=0
5+
--FILE--
6+
<?php
7+
assert(y)[y] ??= y;
8+
?>
9+
--EXPECTF--
10+
Fatal error: Uncaught Error: Undefined constant "y" in %s:%d
11+
Stack trace:
12+
#0 {main}
13+
thrown in %s on line %d

Zend/zend_compile.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4203,6 +4203,10 @@ static void zend_compile_assert(znode *result, zend_ast_list *args, zend_string
42034203
zend_op *opline;
42044204
uint32_t check_op_number = get_next_op_number();
42054205

4206+
/* Assert expression may not be memoized and reused as it may not actually be evaluated. */
4207+
int orig_memoize_mode = CG(memoize_mode);
4208+
CG(memoize_mode) = ZEND_MEMOIZE_NONE;
4209+
42064210
zend_emit_op(NULL, ZEND_ASSERT_CHECK, NULL, NULL);
42074211

42084212
if (fbc && fbc_is_finalized(fbc)) {
@@ -4236,6 +4240,8 @@ static void zend_compile_assert(znode *result, zend_ast_list *args, zend_string
42364240
opline = &CG(active_op_array)->opcodes[check_op_number];
42374241
opline->op2.opline_num = get_next_op_number();
42384242
SET_NODE(opline->result, result);
4243+
4244+
CG(memoize_mode) = orig_memoize_mode;
42394245
} else {
42404246
if (!fbc) {
42414247
zend_string_release_ex(name, 0);

0 commit comments

Comments
 (0)