Skip to content

Commit 00eb847

Browse files
committed
Fix GH-16266: _ZendTestClass::test() segfaults on named parameter
The arg_info is not supposed to be `NULL`, so we it up.
1 parent a5e8ac6 commit 00eb847

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

ext/zend_test/test.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,10 @@ static zend_object *zend_test_class_new(zend_class_entry *class_type)
647647
return obj;
648648
}
649649

650+
static zend_internal_arg_info arginfo_ZendTestClass___call[] = {
651+
{"foo", {0}, NULL},
652+
};
653+
650654
static zend_function *zend_test_class_method_get(zend_object **object, zend_string *name, const zval *key)
651655
{
652656
if (zend_string_equals_literal_ci(name, "test")) {
@@ -659,7 +663,8 @@ static zend_function *zend_test_class_method_get(zend_object **object, zend_stri
659663
}
660664
memset(fptr, 0, sizeof(zend_internal_function));
661665
fptr->type = ZEND_INTERNAL_FUNCTION;
662-
fptr->num_args = 1;
666+
fptr->num_args = sizeof(arginfo_ZendTestClass___call) / sizeof(zend_internal_arg_info);
667+
fptr->arg_info = arginfo_ZendTestClass___call;
663668
fptr->scope = (*object)->ce;
664669
fptr->fn_flags = ZEND_ACC_CALL_VIA_HANDLER;
665670
fptr->function_name = zend_string_copy(name);
@@ -682,7 +687,8 @@ static zend_function *zend_test_class_static_method_get(zend_class_entry *ce, ze
682687
}
683688
memset(fptr, 0, sizeof(zend_internal_function));
684689
fptr->type = ZEND_INTERNAL_FUNCTION;
685-
fptr->num_args = 1;
690+
fptr->num_args = sizeof(arginfo_ZendTestClass___call) / sizeof(zend_internal_arg_info);
691+
fptr->arg_info = arginfo_ZendTestClass___call;
686692
fptr->scope = ce;
687693
fptr->fn_flags = ZEND_ACC_CALL_VIA_HANDLER|ZEND_ACC_STATIC;
688694
fptr->function_name = zend_string_copy(name);

ext/zend_test/tests/gh16266.phpt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
GH-16266 (_ZendTestClass::test() segfaults on named parameter)
3+
--EXTENSIONS--
4+
zend_test
5+
--FILE--
6+
<?php
7+
try {
8+
$o = new _ZendTestClass();
9+
$o->test('a', 'b', c: 'c');
10+
} catch (Error $e) {
11+
echo $e->getMessage(), "\n";
12+
}
13+
try {
14+
_ZendTestClass::test('a', 'b', c: 'c');
15+
} catch (Error $e) {
16+
echo $e->getMessage(), "\n";
17+
}
18+
?>
19+
--EXPECT--
20+
Unknown named parameter $c
21+
Unknown named parameter $c

0 commit comments

Comments
 (0)