[PECL-CVS] [pecl-mail-mailparse] master: Copy header_val null terminator in memcpy, drop explicit terminator
[email protected] (Ilia Alshanetsky via Remi Collet) Sat, 13 Jun 2026 04:59:40 +0000
| Newsgroups | php.pecl.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: Ilia Alshanetsky (iliaal)
Committer: Remi Collet (remicollet)
Date: 2026-06-13T06:59:20+02:00
Commit: https://github.com/php/pecl-mail-mailparse/commit/50f923e16916d3dc73b5d2ac6191a0361cc8e86d
Raw diff: https://github.com/php/pecl-mail-mailparse/commit/50f923e16916d3dc73b5d2ac6191a0361cc8e86d.diff
Copy header_val null terminator in memcpy, drop explicit terminator
header_val is null-terminated, so copying add_len + 1 bytes pulls in its
NUL and makes the separate ZSTR_VAL(joined)[...] = '\0' assignment
redundant. zend_string_alloc already reserves the +1 byte for it.
Suggested by @remicollet in review of GH-58.
Changed paths:
M php_mailparse_mime.c
Diff:
diff --git a/php_mailparse_mime.c b/php_mailparse_mime.c
index b634eec..c6a17ab 100644
--- a/php_mailparse_mime.c
+++ b/php_mailparse_mime.c
@@ -442,8 +442,7 @@ static int php_mimepart_process_header(php_mimepart *part)
memcpy(ZSTR_VAL(joined), ZSTR_VAL(existing), existing_len);
memcpy(ZSTR_VAL(joined) + existing_len, ", ", 2);
- memcpy(ZSTR_VAL(joined) + existing_len + 2, header_val, add_len);
- ZSTR_VAL(joined)[existing_len + 2 + add_len] = '\0';
+ memcpy(ZSTR_VAL(joined) + existing_len + 2, header_val, add_len + 1);
add_assoc_str(&part->headerhash, header_key, joined);
} else {
if((zheaderval = zend_hash_find(Z_ARRVAL_P(&part->headerhash), header_zstring)) != NULL) {