Skip to content

Commit

Permalink
mailinfo: re-fix MIME multipart boundary parsing
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Don Zickus authored and Junio C Hamano committed Aug 19, 2008
1 parent dba9194 commit 289796d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions builtin-mailinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ static void handle_content_type(struct strbuf *line)
message_type = TYPE_OTHER;
if (slurp_attr(line->buf, "boundary=", boundary)) {
strbuf_insert(boundary, 0, "--", 2);
if (content_top++ >= &content[MAX_BOUNDARIES]) {
if (++content_top > &content[MAX_BOUNDARIES]) {
fprintf(stderr, "Too many boundaries to handle\n");
exit(1);
}
Expand Down Expand Up @@ -603,7 +603,7 @@ static void handle_filter(struct strbuf *line);
static int find_boundary(void)
{
while (!strbuf_getline(&line, fin, '\n')) {
if (is_multipart_boundary(&line))
if (*content_top && is_multipart_boundary(&line))
return 1;
}
return 0;
Expand All @@ -626,7 +626,7 @@ static int handle_boundary(void)
/* technically won't happen as is_multipart_boundary()
will fail first. But just in case..
*/
if (content_top-- < content) {
if (--content_top < content) {
fprintf(stderr, "Detected mismatched boundaries, "
"can't recover\n");
exit(1);
Expand Down
1 change: 1 addition & 0 deletions t/t5100/sample.mbox
Original file line number Diff line number Diff line change
Expand Up @@ -500,3 +500,4 @@ index 3e5fe51..aabfe5c 100644
1.6.0.rc2

--=-=-=--

0 comments on commit 289796d

Please sign in to comment.