]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Fixed assert-crash when BODYSTRUCTURE parsing fails due to broken mail...
authorTimo Sirainen <tss@iki.fi>
Tue, 7 Oct 2014 17:29:16 +0000 (20:29 +0300)
committerTimo Sirainen <tss@iki.fi>
Tue, 7 Oct 2014 17:29:16 +0000 (20:29 +0300)
src/lib-storage/index/index-mail.c

index 80fc4bbf8dea1d07f04577a0d92a15dff174834d..bf06d93ee06e4a379d492752d9e8f725bf3d6857 100644 (file)
@@ -847,17 +847,21 @@ index_mail_parse_body_finish(struct index_mail *mail,
                i_stream_ref(parser_input);
                ret = message_parser_deinit(&mail->data.parser_ctx,
                                            &mail->data.parts) < 0 ? 0 : 1;
-               if (parser_input->stream_errno == 0 ||
-                   parser_input->stream_errno == EPIPE) {
-                       /* EPIPE = input already closed. allow the caller to
-                          decide if that is an error or not. (for example we
-                          could be coming here from IMAP APPEND when IMAP
-                          client has closed the connection too early. we
-                          don't want to log an error in that case.) */
-                       i_assert(!success ||
-                                (i_stream_read(parser_input) == -1 &&
-                                 !i_stream_have_bytes_left(parser_input)));
-               } else {
+               if (success && (parser_input->stream_errno == 0 ||
+                               parser_input->stream_errno == EPIPE)) {
+                       /* do one final read, which verifies that the message
+                          size is correct. */
+                       if (i_stream_read(parser_input) != -1 ||
+                           i_stream_have_bytes_left(parser_input))
+                               i_unreached();
+               }
+               /* EPIPE = input already closed. allow the caller to
+                  decide if that is an error or not. (for example we
+                  could be coming here from IMAP APPEND when IMAP
+                  client has closed the connection too early. we
+                  don't want to log an error in that case.) */
+               if (parser_input->stream_errno != 0 &&
+                   parser_input->stream_errno != EPIPE) {
                        index_mail_stream_log_failure_for(mail, parser_input);
                        ret = -1;
                }