dovecot-1.1: Fixed a potential crash if message parsing failed w...

dovecot at dovecot.org dovecot at dovecot.org
Mon Jul 21 19:31:43 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.1/rev/adb772a3fd21
changeset: 7792:adb772a3fd21
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Jul 21 19:31:39 2008 +0300
description:
Fixed a potential crash if message parsing failed while fetching bodystructure.

diffstat:

1 file changed, 11 insertions(+), 6 deletions(-)
src/lib-storage/index/index-mail.c |   17 +++++++++++------

diffs (65 lines):

diff -r b846fe34b515 -r adb772a3fd21 src/lib-storage/index/index-mail.c
--- a/src/lib-storage/index/index-mail.c	Mon Jul 21 18:18:49 2008 +0300
+++ b/src/lib-storage/index/index-mail.c	Mon Jul 21 19:31:39 2008 +0300
@@ -696,20 +696,21 @@ static void index_mail_cache_dates(struc
 		(void)index_mail_cache_sent_date(mail);
 }
 
-static void index_mail_parse_body_finish(struct index_mail *mail,
-					 enum index_cache_field field)
+static int index_mail_parse_body_finish(struct index_mail *mail,
+					enum index_cache_field field)
 {
 	if (message_parser_deinit(&mail->data.parser_ctx,
 				  &mail->data.parts) < 0) {
 		mail_set_cache_corrupted(&mail->mail.mail,
 					 MAIL_FETCH_MESSAGE_PARTS);
-		return;
+		mail->data.parsed_bodystructure = FALSE;
+		return -1;
 	}
 	if (mail->data.no_caching) {
 		/* if we're here because we aborted parsing, don't get any
 		   further or we may crash while generating output from
 		   incomplete data */
-		return;
+		return 0;
 	}
 
 	(void)get_cached_msgpart_sizes(mail);
@@ -719,6 +720,7 @@ static void index_mail_parse_body_finish
 	index_mail_body_parsed_cache_bodystructure(mail, field);
 	index_mail_cache_sizes(mail);
 	index_mail_cache_dates(mail);
+	return 0;
 }
 
 static int index_mail_stream_check_failure(struct index_mail *mail)
@@ -758,7 +760,8 @@ static int index_mail_parse_body(struct 
 			null_message_part_header_callback, NULL);
 	}
 	ret = index_mail_stream_check_failure(mail);
-	index_mail_parse_body_finish(mail, field);
+	if (index_mail_parse_body_finish(mail, field) < 0)
+		ret = -1;
 
 	i_stream_seek(data->stream, old_offset);
 	return ret;
@@ -857,6 +860,8 @@ static int index_mail_parse_bodystructur
 		if (index_mail_parse_body(mail, field) < 0)
 			return -1;
 	}
+	i_assert(data->parts != NULL);
+
 	/* if we didn't want to have the body(structure) cached,
 	   it's still not written. */
 	switch (field) {
@@ -1336,7 +1341,7 @@ void index_mail_cache_parse_deinit(struc
 
 	mail->data.save_bodystructure_body = FALSE;
 	mail->data.parsed_bodystructure = TRUE;
-	index_mail_parse_body_finish(mail, 0);
+	(void)index_mail_parse_body_finish(mail, 0);
 }
 
 void index_mail_update_flags(struct mail *mail, enum modify_type modify_type,


More information about the dovecot-cvs mailing list