Skip to content

Commit 99f5653

Browse files
committed
Fix GH-16908: _ZendTestMagicCallForward does not handle references well
This testing code was never meant to be used this way, but fixing this will at least stop fuzzers from complaining about this, so might still be worthwhile. Closes GH-16919.
1 parent 12ef3da commit 99f5653

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

ext/zend_test/test.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,9 +902,12 @@ static ZEND_METHOD(_ZendTestMagicCallForward, __call)
902902

903903
ZEND_IGNORE_VALUE(arguments);
904904

905-
zval func;
905+
zval func, rv;
906906
ZVAL_STR(&func, name);
907-
call_user_function(NULL, NULL, &func, return_value, 0, NULL);
907+
call_user_function(NULL, NULL, &func, &rv, 0, NULL);
908+
909+
ZVAL_COPY_DEREF(return_value, &rv);
910+
zval_ptr_dtor(&rv);
908911
}
909912

910913
PHP_INI_BEGIN()

ext/zend_test/tests/gh16908.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
GH-16908 (_ZendTestMagicCallForward does not handle references well)
3+
--EXTENSIONS--
4+
zend_test
5+
--FILE--
6+
<?php
7+
$cls = new _ZendTestMagicCallForward();
8+
function &foo() {
9+
}
10+
$cls->foo()->x ??= 42;
11+
?>
12+
--EXPECTF--
13+
Notice: Only variable references should be returned by reference in %s on line %d
14+
15+
Notice: Only variable references should be returned by reference in %s on line %d
16+
17+
Fatal error: Uncaught Error: Attempt to assign property "x" on null in %s:%d
18+
Stack trace:
19+
#0 {main}
20+
thrown in %s on line %d

0 commit comments

Comments
 (0)