changeset 14636:0cb5fdb4c60d

lib-mail: Fixed an edge case with message header parser and very long lines. If the header was exactly a specific number of bytes, the parser thought the header ended there.
author Timo Sirainen <tss@iki.fi>
date Sun, 24 Jun 2012 20:36:05 +0300
parents 45952eee7ad4
children a77ad2346cf0
files src/lib-mail/message-header-parser.c src/lib-mail/test-message-header-parser.c
diffstat 2 files changed, 6 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-mail/message-header-parser.c	Sun Jun 24 19:51:40 2012 +0300
+++ b/src/lib-mail/message-header-parser.c	Sun Jun 24 20:36:05 2012 +0300
@@ -107,7 +107,7 @@
 				return -1;
 			}
 
-			if (size > 0 && !ctx->skip_line &&
+			if (size > 0 && !ctx->skip_line && !continued &&
 			    (msg[0] == '\n' ||
 			     (msg[0] == '\r' && size > 1 && msg[1] == '\n'))) {
 				/* end of headers - this mostly happens just
@@ -154,6 +154,9 @@
 					if (size > 0 && msg[size-1] == '\r')
 						size--;
 				}
+				/* the buffer really has to be more than 2 to
+				   avoid CRLF looping forever */
+				i_assert(size > 0);
 
 				continues = TRUE;
 			}
@@ -249,7 +252,7 @@
 	line->continued = continued;
 	line->crlf_newline = crlf_newline;
 	line->no_newline = no_newline;
-	if (size == 0) {
+	if (size == 0 && !continued) {
 		/* end of headers */
 		line->eoh = TRUE;
 		line->name_len = line->value_len = line->full_value_len = 0;
--- a/src/lib-mail/test-message-header-parser.c	Sun Jun 24 19:51:40 2012 +0300
+++ b/src/lib-mail/test-message-header-parser.c	Sun Jun 24 20:36:05 2012 +0300
@@ -231,7 +231,7 @@
 		test_assert(hdr_size.virtual_size == len + 2);
 	}
 	len = strlen(crlf_str);
-	for (i = 2; i < len; i++) {
+	for (i = 3; i < len; i++) {
 		test_message_header_parser_long_lines_str(crlf_str, i, &hdr_size);
 		test_assert(hdr_size.physical_size == len);
 		test_assert(hdr_size.virtual_size == len);