Skip to content

Commit 971e5c5

Browse files
committed
Fixed bug #79783
Make sure we don't drop the by-reference check when passing the result of a VM builtin function.
1 parent a58d865 commit 971e5c5

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ PHP NEWS
1212
- Core:
1313
. Fixed bug #79740 (serialize() and unserialize() methods can not be called
1414
statically). (Nikita)
15+
. Fixede bug #79783 (Segfault in php_str_replace_common). (Nikita)
1516

1617
- Fileinfo:
1718
. Fixed bug #79756 (finfo_file crash (FILEINFO_MIME)). (cmb)

Zend/tests/bug79783.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
Bug #79783: Segfault in php_str_replace_common
3+
--FILE--
4+
<?php
5+
str_replace("a", "b", "c", strlen("d"));
6+
?>
7+
--EXPECTF--
8+
Fatal error: Uncaught Error: Cannot pass parameter 4 by reference in %s:%d
9+
Stack trace:
10+
#0 {main}
11+
thrown in %s on line %d

Zend/zend_compile.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3009,7 +3009,11 @@ uint32_t zend_compile_args(zend_ast *ast, zend_function *fbc) /* {{{ */
30093009
zend_compile_var(&arg_node, arg, BP_VAR_R, 0);
30103010
if (arg_node.op_type & (IS_CONST|IS_TMP_VAR)) {
30113011
/* Function call was converted into builtin instruction */
3012-
opcode = ZEND_SEND_VAL;
3012+
if (!fbc || ARG_MUST_BE_SENT_BY_REF(fbc, arg_num)) {
3013+
opcode = ZEND_SEND_VAL_EX;
3014+
} else {
3015+
opcode = ZEND_SEND_VAL;
3016+
}
30133017
} else {
30143018
if (fbc) {
30153019
if (ARG_MUST_BE_SENT_BY_REF(fbc, arg_num)) {

0 commit comments

Comments
 (0)