Skip to content

Commit 08e6c20

Browse files
committed
Fix null pointer deref in compile_return()
Fixes oss-fuzz #24387.
1 parent 3b5b288 commit 08e6c20

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

Zend/tests/return_ref_none.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
Argument-less return from by-ref function
3+
--FILE--
4+
<?php
5+
6+
function &test() {
7+
return;
8+
}
9+
10+
$ref =& test();
11+
12+
?>
13+
--EXPECTF--
14+
Notice: Only variable references should be returned by reference in %s on line %d

Zend/zend_compile.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4631,14 +4631,14 @@ void zend_compile_return(zend_ast *ast) /* {{{ */
46314631
by_ref = 0;
46324632
}
46334633

4634-
if (by_ref && zend_ast_is_short_circuited(expr_ast)) {
4635-
zend_error_noreturn(E_COMPILE_ERROR, "Cannot take reference of a nullsafe chain");
4636-
}
4637-
46384634
if (!expr_ast) {
46394635
expr_node.op_type = IS_CONST;
46404636
ZVAL_NULL(&expr_node.u.constant);
46414637
} else if (by_ref && zend_is_variable(expr_ast)) {
4638+
if (zend_ast_is_short_circuited(expr_ast)) {
4639+
zend_error_noreturn(E_COMPILE_ERROR, "Cannot take reference of a nullsafe chain");
4640+
}
4641+
46424642
zend_compile_var(&expr_node, expr_ast, BP_VAR_W, 1);
46434643
} else {
46444644
zend_compile_expr(&expr_node, expr_ast);

0 commit comments

Comments
 (0)