Skip to content

Commit ac3ff5b

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Fix use-of-uninitialized-value with ??= on assert
2 parents a5e89c5 + 84a2e48 commit ac3ff5b

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
@@ -12,6 +12,7 @@ PHP NEWS
1212
. Fixed oss-fuzz #60011 (Mis-compilation of by-reference nullsafe operator).
1313
(ilutov)
1414
. Fixed line number of JMP instruction over else block. (ilutov)
15+
. Fixed use-of-uninitialized-value with ??= on assert. (ilutov)
1516

1617
- Date:
1718
. Fixed bug GH-11368 (Date modify returns invalid datetime). (Derick)

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
@@ -4095,6 +4095,10 @@ static void zend_compile_assert(znode *result, zend_ast_list *args, zend_string
40954095
zend_op *opline;
40964096
uint32_t check_op_number = get_next_op_number();
40974097

4098+
/* Assert expression may not be memoized and reused as it may not actually be evaluated. */
4099+
int orig_memoize_mode = CG(memoize_mode);
4100+
CG(memoize_mode) = ZEND_MEMOIZE_NONE;
4101+
40984102
zend_emit_op(NULL, ZEND_ASSERT_CHECK, NULL, NULL);
40994103

41004104
if (fbc && fbc_is_finalized(fbc)) {
@@ -4128,6 +4132,8 @@ static void zend_compile_assert(znode *result, zend_ast_list *args, zend_string
41284132
opline = &CG(active_op_array)->opcodes[check_op_number];
41294133
opline->op2.opline_num = get_next_op_number();
41304134
SET_NODE(opline->result, result);
4135+
4136+
CG(memoize_mode) = orig_memoize_mode;
41314137
} else {
41324138
if (!fbc) {
41334139
zend_string_release_ex(name, 0);

0 commit comments

Comments
 (0)