[PHP-CVS] [php-src] master: Merge branch 'PHP-8.4' into PHP-8.5
[email protected] (Ilia Alshanetsky) Fri, 31 Jul 2026 16:17:02 +0000
| Newsgroups | php.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: Ilia Alshanetsky (iliaal)
Date: 2026-07-31T12:11:08-04:00
Commit: https://github.com/php/php-src/commit/cc0ff7e0a05eddb0a95a59346c3409323a181c91
Raw diff: https://github.com/php/php-src/commit/cc0ff7e0a05eddb0a95a59346c3409323a181c91.diff
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
Avoid truncation on null bytes in class and function names
Changed paths:
A ext/reflection/tests/gh22681/ReflectionClass_name.phpt
A ext/reflection/tests/gh22681/ReflectionFunctionAbstract_name.phpt
M ext/reflection/php_reflection.c
Diff:
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index 13723ed5173f..94f908428891 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -966,7 +966,8 @@ static void _function_string(smart_str *str, zend_function *fptr, zend_class_ent
if (fptr->op_array.fn_flags & ZEND_ACC_RETURN_REFERENCE) {
smart_str_appendc(str, '&');
}
- smart_str_append_printf(str, "%s ] {\n", ZSTR_VAL(fptr->common.function_name));
+ smart_str_append(str, fptr->common.function_name);
+ smart_str_appends(str, " ] {\n");
/* The information where a function is declared is only available for user classes */
if (fptr->type == ZEND_USER_FUNCTION) {
smart_str_append_printf(str, "%s @@ %s %d - %d\n", indent,
diff --git a/ext/reflection/tests/gh22681/ReflectionClass_name.phpt b/ext/reflection/tests/gh22681/ReflectionClass_name.phpt
new file mode 100644
index 000000000000..c1c24b5c2e5f
--- /dev/null
+++ b/ext/reflection/tests/gh22681/ReflectionClass_name.phpt
@@ -0,0 +1,32 @@
+--TEST--
+GH-22681: null bytes in name truncate ReflectionClass::__toString()
+--FILE--
+<?php
+
+$obj = new class {};
+
+$r = new ReflectionClass($obj);
+echo $r;
+var_dump( $r->getName() );
+
+?>
+--EXPECTF--
+Class [ <user> class class@anonymous%0%s ] {
+ @@ %s %d-%d
+
+ - Constants [0] {
+ }
+
+ - Static properties [0] {
+ }
+
+ - Static methods [0] {
+ }
+
+ - Properties [0] {
+ }
+
+ - Methods [0] {
+ }
+}
+string(%d) "class@anonymous%0%s"
diff --git a/ext/reflection/tests/gh22681/ReflectionFunctionAbstract_name.phpt b/ext/reflection/tests/gh22681/ReflectionFunctionAbstract_name.phpt
new file mode 100644
index 000000000000..946dd164f3ad
--- /dev/null
+++ b/ext/reflection/tests/gh22681/ReflectionFunctionAbstract_name.phpt
@@ -0,0 +1,21 @@
+--TEST--
+GH-22681: null bytes in name truncate ReflectionFunction::__toString()
+--FILE--
+<?php
+
+$obj = new class {
+ public function make(): Closure {
+ return function () {};
+ }
+};
+
+$r = new ReflectionFunction($obj->make());
+echo $r;
+var_dump( $r->getName() );
+
+?>
+--EXPECTF--
+Closure [ <user> public method {closure:class@anonymous%0%s::make():%d} ] {
+ @@ %s %d - %d
+}
+string(%d) "{closure:class@anonymous%0%s::make():%d}"