git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Don Zickus <dzickus@redhat.com>
To: git@vger.kernel.org
Cc: Don Zickus <dzickus@redhat.com>
Subject: [PATCH] Allow emails with boundaries to work again
Date: Wed, 13 Aug 2008 18:45:59 -0400	[thread overview]
Message-ID: <1218667559-26618-1-git-send-email-dzickus@redhat.com> (raw)

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.

Signed-Off-by: Don Zickus <dzickus@redhat.com>
---
 builtin-mailinfo.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/builtin-mailinfo.c b/builtin-mailinfo.c
index 6ae2bf3..0209e82 100644
--- a/builtin-mailinfo.c
+++ b/builtin-mailinfo.c
@@ -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);
 		}
@@ -626,7 +626,7 @@ again:
 		/* 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);
@@ -635,9 +635,11 @@ again:
 		strbuf_release(&newline);
 
 		/* skip to the next boundary */
-		if (!find_boundary())
-			return 0;
-		goto again;
+		if (*content_top) {
+			if (!find_boundary())
+				return 0;
+			goto again;
+		}
 	}
 
 	/* set some defaults */
-- 
1.5.5.1

             reply	other threads:[~2008-08-13 22:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-08-13 22:45 Don Zickus [this message]
2008-08-13 23:45 ` [PATCH] Allow emails with boundaries to work again Junio C Hamano
2008-08-14  0:56   ` Don Zickus
2008-08-14  1:36 ` Junio C Hamano
2008-08-14  1:56   ` Don Zickus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1218667559-26618-1-git-send-email-dzickus@redhat.com \
    --to=dzickus@redhat.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).