Skip to content

Fix use-of-uninitialized-value with ??= on assert #11581

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Zend/tests/gh11580.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
GH-11580: assert() with ??= operator can lead to use-of-uninitialized-value
--INI--
zend.assertions=0
--FILE--
<?php
assert(y)[y] ??= y;
?>
--EXPECTF--
Fatal error: Uncaught Error: Undefined constant "y" in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d
6 changes: 6 additions & 0 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -4083,6 +4083,10 @@ static void zend_compile_assert(znode *result, zend_ast_list *args, zend_string
zend_op *opline;
uint32_t check_op_number = get_next_op_number();

/* Assert expression may not be memoized and reused as it may not actually be evaluated. */
int orig_memoize_mode = CG(memoize_mode);
CG(memoize_mode) = ZEND_MEMOIZE_NONE;

zend_emit_op(NULL, ZEND_ASSERT_CHECK, NULL, NULL);

if (fbc && fbc_is_finalized(fbc)) {
Expand Down Expand Up @@ -4116,6 +4120,8 @@ static void zend_compile_assert(znode *result, zend_ast_list *args, zend_string
opline = &CG(active_op_array)->opcodes[check_op_number];
opline->op2.opline_num = get_next_op_number();
SET_NODE(opline->result, result);

CG(memoize_mode) = orig_memoize_mode;
} else {
if (!fbc) {
zend_string_release_ex(name, 0);
Expand Down