summaryrefslogtreecommitdiff
path: root/builtin-mailinfo.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-08-09 01:17:24 -0700
committerJunio C Hamano <gitster@pobox.com>2008-08-09 01:26:35 -0700
commita9fd1383a73878284d4157b20ac7c735e876102e (patch)
tree79120c2528ed7f6396c666cf8a3d5bd3c01c9b6b /builtin-mailinfo.c
parent01144f20955bfbb6463c9649d90f411839ad1617 (diff)
downloadgit-a9fd1383a73878284d4157b20ac7c735e876102e.tar.gz
mailinfo: fix MIME multi-part message boundary handling
After finding a MIME multi-part message boundary line, the handle_body() function is supposed to first flush any accumulated contents from the previous part to the output stream. However, the code mistakenly output the boundary line it found. The old code that used one global, fixed-length buffer line[] used an alternate static buffer newline[] for keeping track of this accumulated contents and flushed newline[] upon seeing the boundary; when 3b6121f (git-mailinfo: use strbuf's instead of fixed buffers, 2008-07-13) converted a fixed-length buffer in this program to use strbuf,these two buffers were converted to "line" and "prev" (the latter of which now has a much more sensible name) strbufs, but the code mistakenly flushed "line" (which contains the boundary we have just found), instead of "prev". This resulted in the first boundary to be output in front of the first line of the message. The rewritten implementation of handle_boundary() lost the terminating newline; this would then result in the second line of the message to be stuck with the first line. The is_multipart_boundary() was designed to catch both the internal boundary and the terminating one (the one with trailing "--"); this also was broken with the rewrite, and the code in the handle_boundary() to handle the terminating boundary was never triggered. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-mailinfo.c')
-rw-r--r--builtin-mailinfo.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
index f974b9df96..3577382d70 100644
--- a/builtin-mailinfo.c
+++ b/builtin-mailinfo.c
@@ -203,7 +203,8 @@ static void handle_content_transfer_encoding(const struct strbuf *line)
static int is_multipart_boundary(const struct strbuf *line)
{
- return !strbuf_cmp(line, *content_top);
+ return (((*content_top)->len <= line->len) &&
+ !memcmp(line->buf, (*content_top)->buf, (*content_top)->len));
}
static void cleanup_subject(struct strbuf *subject)
@@ -649,8 +650,11 @@ again:
check_header(&line, p_hdr_data, 0);
strbuf_release(&newline);
- /* eat the blank line after section info */
- return (strbuf_getline(&line, fin, '\n') == 0);
+ /* replenish line */
+ if (strbuf_getline(&line, fin, '\n'))
+ return 0;
+ strbuf_addch(&line, '\n');
+ return 1;
}
static inline int patchbreak(const struct strbuf *line)
@@ -757,9 +761,10 @@ static void handle_body(void)
/* process any boundary lines */
if (*content_top && is_multipart_boundary(&line)) {
/* flush any leftover */
- if (line.len)
- handle_filter(&line);
-
+ if (prev.len) {
+ handle_filter(&prev);
+ strbuf_reset(&prev);
+ }
if (!handle_boundary())
goto handle_body_out;
}