Skip to content

Commit c0e3886

Browse files
nielsdoscharmitro
authored andcommitted
Fix phpGH-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 phpGH-16919.
1 parent 2b40145 commit c0e3886

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
@@ -1114,9 +1114,12 @@ static ZEND_METHOD(_ZendTestMagicCallForward, __call)
11141114

11151115
ZEND_IGNORE_VALUE(arguments);
11161116

1117-
zval func;
1117+
zval func, rv;
11181118
ZVAL_STR(&func, name);
1119-
call_user_function(NULL, NULL, &func, return_value, 0, NULL);
1119+
call_user_function(NULL, NULL, &func, &rv, 0, NULL);
1120+
1121+
ZVAL_COPY_DEREF(return_value, &rv);
1122+
zval_ptr_dtor(&rv);
11201123
}
11211124

11221125
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)