[php-src] PHP-8.5: GH-22681: avoid truncation on null bytes in `ReflectionEnum::__toString()`
Daniel Scherzer <[email protected]>
| Newsgroups | gmane.comp.php.cvs.general |
|---|---|
| Message-ID | <[email protected]> |
Author: Daniel Scherzer (DanielEScherzer)
Date: 2026-07-14T06:36:49-07:00
Commit: https://github.com/php/php-src/commit/1b2c0abbdb333cbe350aff69904f3312c55c18f1
Raw diff: https://github.com/php/php-src/commit/1b2c0abbdb333cbe350aff69904f3312c55c18f1.diff
GH-22681: avoid truncation on null bytes in `ReflectionEnum::__toString()`
Changed paths:
M ext/reflection/php_reflection.c
M ext/reflection/tests/gh22681/ReflectionEnum_backed_value.phpt
M ext/reflection/tests/gh22681/ReflectionEnum_case_doc_comment.phpt
Diff:
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index a3e996b654c1..bf7fde62d499 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -677,7 +677,9 @@ static void _enum_case_string(smart_str *str, const zend_string *name, zend_clas
}
if (c->doc_comment) {
- smart_str_append_printf(str, "%s%s\n", indent, ZSTR_VAL(c->doc_comment));
+ smart_str_appends(str, indent);
+ smart_str_append(str, c->doc_comment);
+ smart_str_appendc(str, '\n');
}
smart_str_append_printf(str, "%sCase %s", indent, ZSTR_VAL(name));
if (c->ce->enum_backing_type == IS_UNDEF) {
@@ -691,7 +693,9 @@ static void _enum_case_string(smart_str *str, const zend_string *name, zend_clas
zval *enum_val = zend_enum_fetch_case_value(Z_OBJ(c->value));
zend_string *tmp_value_str;
zend_string *value_str = zval_get_tmp_string(enum_val, &tmp_value_str);
- smart_str_append_printf(str, " = %s\n", ZSTR_VAL(value_str));
+ smart_str_appends(str, " = ");
+ smart_str_append(str, value_str);
+ smart_str_appendc(str, '\n');
zend_tmp_string_release(tmp_value_str);
}
}
diff --git a/ext/reflection/tests/gh22681/ReflectionEnum_backed_value.phpt b/ext/reflection/tests/gh22681/ReflectionEnum_backed_value.phpt
index 8131a3adafed..f28c39daa100 100644
--- a/ext/reflection/tests/gh22681/ReflectionEnum_backed_value.phpt
+++ b/ext/reflection/tests/gh22681/ReflectionEnum_backed_value.phpt
@@ -16,7 +16,7 @@ Enum [ <user> enum Demo: string implements UnitEnum, BackedEnum ] {
@@ %s %d-%d
- Enum cases [1] {
- Case DEMO = F
+ Case DEMO = F%0oo
}
- Constants [0] {
diff --git a/ext/reflection/tests/gh22681/ReflectionEnum_case_doc_comment.phpt b/ext/reflection/tests/gh22681/ReflectionEnum_case_doc_comment.phpt
index 68bde0bed637..3945ad8639e7 100644
--- a/ext/reflection/tests/gh22681/ReflectionEnum_case_doc_comment.phpt
+++ b/ext/reflection/tests/gh22681/ReflectionEnum_case_doc_comment.phpt
@@ -20,7 +20,7 @@ Enum [ <user> enum Demo implements UnitEnum ] {
@@ %s(%d) : eval()'d code %d-%d
- Enum cases [1] {
- /** F
+ /** F%0oo */
Case C
}