[php-src] master: GH-22658: avoid truncation on null bytes in `ReflectionConstant::__toString()`
Daniel Scherzer <[email protected]>
| Newsgroups | gmane.comp.php.cvs.general |
|---|---|
| Message-ID | <[email protected]> |
Author: Daniel Scherzer (DanielEScherzer)
Date: 2026-07-10T07:21:00-07:00
Commit: https://github.com/php/php-src/commit/ed3e06a6738b5ab9b7ed8e92cda79832cd172ea1
Raw diff: https://github.com/php/php-src/commit/ed3e06a6738b5ab9b7ed8e92cda79832cd172ea1.diff
GH-22658: avoid truncation on null bytes in `ReflectionConstant::__toString()`
Changed paths:
M ext/reflection/php_reflection.c
M ext/reflection/tests/ReflectionConstant_null_byte_value.phpt
Diff:
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index e747a642778c..661b1eb1f3a4 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -585,7 +585,7 @@ static void _const_string(smart_str *str, const char *name, zval *value, const c
if (Z_TYPE_P(value) == IS_ARRAY) {
smart_str_append(str, ZSTR_KNOWN(ZEND_STR_ARRAY_CAPITALIZED));
} else if (Z_TYPE_P(value) == IS_STRING) {
- smart_str_appends(str, Z_STRVAL_P(value));
+ smart_str_append(str, Z_STR_P(value));
} else {
zend_string *tmp_value_str;
zend_string *value_str = zval_get_tmp_string(value, &tmp_value_str);
diff --git a/ext/reflection/tests/ReflectionConstant_null_byte_value.phpt b/ext/reflection/tests/ReflectionConstant_null_byte_value.phpt
index 5e1b855eed05..8b6a8e85c2fc 100644
--- a/ext/reflection/tests/ReflectionConstant_null_byte_value.phpt
+++ b/ext/reflection/tests/ReflectionConstant_null_byte_value.phpt
@@ -10,5 +10,5 @@ var_dump( $r->getValue() );
?>
--EXPECTF--
-Constant [ string DEMO ] { f }
+Constant [ string DEMO ] { f%0oo }
string(4) "f%0oo"