Skip to content

Commit b6537d8

Browse files
peffgitster
authored andcommitted
mailinfo: treat header values as C strings
We read each header line into a strbuf, which means that we could in theory handle header values with embedded NUL bytes. But in practice, the values we parse out are passed to decode_header(), which uses strstr(), strchr(), etc. And we would not expect such bytes anyway; they are forbidden by RFC822, etc. and any non-ASCII characters should be encoded with RFC2047 encoding. So let's switch to using strbuf_addstr(), which saves us some length computations (and will enable further cleanups in this code). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 517b605 commit b6537d8

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

mailinfo.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ static int check_header(struct mailinfo *mi,
557557
/* Unwrap inline B and Q encoding, and optionally
558558
* normalize the meta information to utf8.
559559
*/
560-
strbuf_add(&sb, line->buf + len + 2, line->len - len - 2);
560+
strbuf_addstr(&sb, line->buf + len + 2);
561561
decode_header(mi, &sb);
562562
handle_header(&hdr_data[i], &sb);
563563
ret = 1;
@@ -568,23 +568,23 @@ static int check_header(struct mailinfo *mi,
568568
/* Content stuff */
569569
if (cmp_header(line, "Content-Type")) {
570570
len = strlen("Content-Type: ");
571-
strbuf_add(&sb, line->buf + len, line->len - len);
571+
strbuf_addstr(&sb, line->buf + len);
572572
decode_header(mi, &sb);
573573
handle_content_type(mi, &sb);
574574
ret = 1;
575575
goto check_header_out;
576576
}
577577
if (cmp_header(line, "Content-Transfer-Encoding")) {
578578
len = strlen("Content-Transfer-Encoding: ");
579-
strbuf_add(&sb, line->buf + len, line->len - len);
579+
strbuf_addstr(&sb, line->buf + len);
580580
decode_header(mi, &sb);
581581
handle_content_transfer_encoding(mi, &sb);
582582
ret = 1;
583583
goto check_header_out;
584584
}
585585
if (cmp_header(line, "Message-Id")) {
586586
len = strlen("Message-Id: ");
587-
strbuf_add(&sb, line->buf + len, line->len - len);
587+
strbuf_addstr(&sb, line->buf + len);
588588
decode_header(mi, &sb);
589589
if (mi->add_message_id)
590590
mi->message_id = strbuf_detach(&sb, NULL);

0 commit comments

Comments
 (0)