Skip to content

Commit 289796d

Browse files
dzickusrhgitster
authored andcommitted
mailinfo: re-fix MIME multipart boundary parsing
Recent changes to is_multipart_boundary() caused git-mailinfo to segfault. The reason was after handling the end of the boundary the code tried to look for another boundary. Because the boundary list was empty, dereferencing the pointer to the top of the boundary caused the program to go boom. The fix is to check to see if the list is empty and if so go on its merry way instead of looking for another boundary. I also fixed a couple of increments and decrements that didn't look correct relating to content_top. The boundary test case was updated to catch future problems like this again. Signed-off-by: Don Zickus <dzickus@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent dba9194 commit 289796d

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

builtin-mailinfo.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ static void handle_content_type(struct strbuf *line)
175175
message_type = TYPE_OTHER;
176176
if (slurp_attr(line->buf, "boundary=", boundary)) {
177177
strbuf_insert(boundary, 0, "--", 2);
178-
if (content_top++ >= &content[MAX_BOUNDARIES]) {
178+
if (++content_top > &content[MAX_BOUNDARIES]) {
179179
fprintf(stderr, "Too many boundaries to handle\n");
180180
exit(1);
181181
}
@@ -603,7 +603,7 @@ static void handle_filter(struct strbuf *line);
603603
static int find_boundary(void)
604604
{
605605
while (!strbuf_getline(&line, fin, '\n')) {
606-
if (is_multipart_boundary(&line))
606+
if (*content_top && is_multipart_boundary(&line))
607607
return 1;
608608
}
609609
return 0;
@@ -626,7 +626,7 @@ static int handle_boundary(void)
626626
/* technically won't happen as is_multipart_boundary()
627627
will fail first. But just in case..
628628
*/
629-
if (content_top-- < content) {
629+
if (--content_top < content) {
630630
fprintf(stderr, "Detected mismatched boundaries, "
631631
"can't recover\n");
632632
exit(1);

t/t5100/sample.mbox

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,3 +500,4 @@ index 3e5fe51..aabfe5c 100644
500500
1.6.0.rc2
501501

502502
--=-=-=--
503+

0 commit comments

Comments
 (0)