dovecot-2.2: lib-mail: Fixed an edge case with message header pa...

dovecot at dovecot.org dovecot at dovecot.org
Sun Jun 24 20:48:58 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/0cb5fdb4c60d
changeset: 14636:0cb5fdb4c60d
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Jun 24 20:36:05 2012 +0300
description:
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.

diffstat:

 src/lib-mail/message-header-parser.c      |  7 +++++--
 src/lib-mail/test-message-header-parser.c |  2 +-
 2 files changed, 6 insertions(+), 3 deletions(-)

diffs (43 lines):

diff -r 45952eee7ad4 -r 0cb5fdb4c60d src/lib-mail/message-header-parser.c
--- 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;
diff -r 45952eee7ad4 -r 0cb5fdb4c60d src/lib-mail/test-message-header-parser.c
--- 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);


More information about the dovecot-cvs mailing list