Skip to content

Commit 8720063

Browse files
committed
Fix propagation of ZEND_ACC_RETURN_REFERENCE for call trampoline
Fixes GH-16515 Closes GH-16529
1 parent f9ce5e7 commit 8720063

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ PHP NEWS
1313
. Fixed bug GH-16168 (php 8.1 and earlier crash immediately when compiled
1414
with Xcode 16 clang on macOS 15). (nielsdos)
1515
. Fixed bug GH-16371 (Assertion failure in Zend/zend_weakrefs.c:646). (Arnaud)
16+
. Fixed bug GH-16515 (Incorrect propagation of ZEND_ACC_RETURN_REFERENCE for
17+
call trampoline). (ilutov)
1618

1719
- Curl:
1820
. Fixed bug GH-16302 (CurlMultiHandle holds a reference to CurlHandle if

Zend/tests/gh16515.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
GH-16515: Incorrect propagation of ZEND_ACC_RETURN_REFERENCE for call trampoline
3+
--FILE--
4+
<?php
5+
6+
namespace Foo;
7+
8+
class Foo {
9+
public function &__call($method, $args) {}
10+
}
11+
12+
call_user_func((new Foo)->bar(...));
13+
14+
?>
15+
--EXPECTF--
16+
Notice: Only variable references should be returned by reference in %s on line %d

Zend/zend_closures.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ void zend_closure_from_frame(zval *return_value, zend_execute_data *call) { /* {
845845

846846
memset(&trampoline, 0, sizeof(zend_internal_function));
847847
trampoline.type = ZEND_INTERNAL_FUNCTION;
848-
trampoline.fn_flags = mptr->common.fn_flags & ZEND_ACC_STATIC;
848+
trampoline.fn_flags = mptr->common.fn_flags & (ZEND_ACC_STATIC|ZEND_ACC_RETURN_REFERENCE);
849849
trampoline.handler = zend_closure_call_magic;
850850
trampoline.function_name = mptr->common.function_name;
851851
trampoline.scope = mptr->common.scope;

Zend/zend_object_handlers.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1281,7 +1281,10 @@ ZEND_API zend_function *zend_get_call_trampoline_func(zend_class_entry *ce, zend
12811281
func->arg_flags[0] = 0;
12821282
func->arg_flags[1] = 0;
12831283
func->arg_flags[2] = 0;
1284-
func->fn_flags = ZEND_ACC_CALL_VIA_TRAMPOLINE | ZEND_ACC_PUBLIC | ZEND_ACC_VARIADIC;
1284+
func->fn_flags = ZEND_ACC_CALL_VIA_TRAMPOLINE
1285+
| ZEND_ACC_PUBLIC
1286+
| ZEND_ACC_VARIADIC
1287+
| (fbc->common.fn_flags & ZEND_ACC_RETURN_REFERENCE);
12851288
if (is_static) {
12861289
func->fn_flags |= ZEND_ACC_STATIC;
12871290
}

0 commit comments

Comments
 (0)