Skip to content

Commit 3f7bfaf

Browse files
authored
uri: Fix RFC3986 to_string implementation with ExcludeFragment returning non-terminated strings (php#20811)
zend_string_truncate() doesn't put a NUL byte. Right now this doesn't matter as this code path is only hittable via the equals() method, but if other extension (or future other code) starts using this code path, then it can be problematic as all user-exposed zend_strings need to end with a NUL byte.
1 parent d9b02e4 commit 3f7bfaf

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

ext/uri/uri_parser_rfc3986.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@ ZEND_ATTRIBUTE_NONNULL static zend_string *php_uri_parser_rfc3986_to_string(void
595595
const char *pos = zend_memrchr(ZSTR_VAL(uri_string), '#', ZSTR_LEN(uri_string));
596596
if (pos != NULL) {
597597
uri_string = zend_string_truncate(uri_string, (pos - ZSTR_VAL(uri_string)), false);
598+
ZSTR_VAL(uri_string)[ZSTR_LEN(uri_string)] = '\0';
598599
}
599600
}
600601

0 commit comments

Comments
 (0)