git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] Allow emails with boundaries to work again

From
DZDon Zickus <dzickus@redhat.com>
Date
Aug 13, 2008, 22:45 UTC
Message-ID
<1218667559-26618-1-git-send-email-dzickus@redhat.com>

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
Next: Junio C Hamano
Message 1 of 5 in “Allow emails with boundaries to work again”
  1. Allow emails with boundaries to work againDon Zickus, Aug 13, 2008
  2. Junio C HamanoAug 13, 2008
  3. Don ZickusAug 14, 2008
  4. Junio C HamanoAug 14, 2008
  5. Don ZickusAug 14, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.