Skip to content

Fix OSS-Fuzz #69765 #14716

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 2 commits 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
10 changes: 10 additions & 0 deletions Zend/tests/oss-fuzz-69765.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
OSS-Fuzz #69765: yield reference to nullsafe chain
--FILE--
<?php
function &test($object) {
yield $object->y?->y;
}
?>
--EXPECTF--
Fatal error: Cannot take reference of a nullsafe chain in %s on line %d
22 changes: 12 additions & 10 deletions Zend/zend_compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -2312,6 +2312,13 @@ static bool zend_ast_is_short_circuited(const zend_ast *ast)
}
}

static void zend_assert_not_short_circuited(const zend_ast *ast)
{
if (zend_ast_is_short_circuited(ast)) {
zend_error_noreturn(E_COMPILE_ERROR, "Cannot take reference of a nullsafe chain");
}
}

/* Mark nodes that are an inner part of a short-circuiting chain.
* We should not perform a "commit" on them, as it will be performed by the outer-most node.
* We do this to avoid passing down an argument in various compile functions. */
Expand Down Expand Up @@ -3304,9 +3311,8 @@ static void zend_compile_assign(znode *result, zend_ast *ast) /* {{{ */
if (!zend_is_variable_or_call(expr_ast)) {
zend_error_noreturn(E_COMPILE_ERROR,
"Cannot assign reference to non referenceable value");
} else if (zend_ast_is_short_circuited(expr_ast)) {
zend_error_noreturn(E_COMPILE_ERROR,
"Cannot take reference of a nullsafe chain");
} else {
zend_assert_not_short_circuited(expr_ast);
}

zend_compile_var(&expr_node, expr_ast, BP_VAR_W, 1);
Expand Down Expand Up @@ -3348,9 +3354,7 @@ static void zend_compile_assign_ref(znode *result, zend_ast *ast) /* {{{ */
zend_error_noreturn(E_COMPILE_ERROR, "Cannot re-assign $this");
}
zend_ensure_writable_variable(target_ast);
if (zend_ast_is_short_circuited(source_ast)) {
zend_error_noreturn(E_COMPILE_ERROR, "Cannot take reference of a nullsafe chain");
}
zend_assert_not_short_circuited(source_ast);
if (is_globals_fetch(source_ast)) {
zend_error_noreturn(E_COMPILE_ERROR, "Cannot acquire reference to $GLOBALS");
}
Expand Down Expand Up @@ -5026,10 +5030,7 @@ static void zend_compile_return(zend_ast *ast) /* {{{ */
expr_node.op_type = IS_CONST;
ZVAL_NULL(&expr_node.u.constant);
} else if (by_ref && zend_is_variable(expr_ast)) {
if (zend_ast_is_short_circuited(expr_ast)) {
zend_error_noreturn(E_COMPILE_ERROR, "Cannot take reference of a nullsafe chain");
}

zend_assert_not_short_circuited(expr_ast);
zend_compile_var(&expr_node, expr_ast, BP_VAR_W, 1);
} else {
zend_compile_expr(&expr_node, expr_ast);
Expand Down Expand Up @@ -9329,6 +9330,7 @@ static void zend_compile_yield(znode *result, zend_ast *ast) /* {{{ */

if (value_ast) {
if (returns_by_ref && zend_is_variable(value_ast)) {
zend_assert_not_short_circuited(value_ast);
zend_compile_var(&value_node, value_ast, BP_VAR_W, 1);
} else {
zend_compile_expr(&value_node, value_ast);
Expand Down
Loading