Blob Blame History Raw
Index: bogofilter/src/mime.c
===================================================================
--- bogofilter/src/mime.c	(revision 7022)
+++ bogofilter/src/mime.c	(revision 7023)
@@ -279,6 +279,25 @@
     mime_push(parent);
 }
 
+static bool is_final_boundary(
+	const byte	*ins,
+	size_t		 inlen,
+	size_t		 blen
+)
+{
+    if (inlen >= 5
+	    && inlen >= blen + 2
+	    && ins[0] == '-'
+	    && ins[1] == '-'
+	    && ins[blen+2] == '-'
+	    && ins[blen+3] == '-')
+    {
+	return true;
+    }
+    return false;
+}
+
+
 /**
  * Check if the line given in \a boundary is a boundary of one of the
  * outer MIME containers and store the results in \a b.
@@ -301,28 +320,18 @@
 	       (buf[blen - 1] == '\r' || buf[blen - 1] == '\n'))
 	    blen--;
 
-	/* skip initial -- */
-	buf += 2;
-	blen -= 2;
-
-	/* skip and note ending --, if any */
-	if (blen > 2 && buf[blen - 1] == '-' && buf[blen - 2] == '-') {
-	    b->is_final = true;
-	    blen -= 2;
-	} else {
-	    b->is_final = false;
-	}
-
 	/* search stack for matching boundary, in reverse order */
 	for (ptr = mime_stack_bot; ptr != NULL; ptr = ptr->parent)
 	{
 	    if (is_mime_container(ptr)
 		&& ptr->boundary != NULL
-		&& ptr->boundary_len == blen
-		&& (memcmp(ptr->boundary, buf, blen) == 0))
+		&& (ptr->boundary_len + 2 == blen
+		    || ptr->boundary_len + 4 == blen)
+		&& (memcmp(ptr->boundary, buf + 2, ptr->boundary_len) == 0))
 	    {
 		b->depth = ptr->depth;
 		b->is_valid = true;
+		b->is_final = is_final_boundary(buf, blen, ptr->boundary_len);
 		break;
 	    }
 	}
Index: bogofilter/NEWS
===================================================================
--- bogofilter/NEWS	(revision 7022)
+++ bogofilter/NEWS	(revision 7023)
@@ -15,6 +15,15 @@
 
 -------------------------------------------------------------------------------
 
+	2015-02-25
+
+	* Fix the lexer to handle MIME multipart messages properly when the
+	  boundary ended in "--".  The parser would previously never find the
+	  MIME parts because it mistook all boundaries ending in two dashes to
+	  be the final boundary of the multipart, rather than checking if the
+	  two dashes were extra.
+	  Reported by Matt Garretson to the bogofilter mailing list today.
+
 	2014-07-10
 
 	* Take patch from Julius Plenz to fix a bug in the charset converter