]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
Don't crash in assert() with corrupted index file.
authorTimo Sirainen <tss@iki.fi>
Sun, 2 May 2004 12:57:29 +0000 (15:57 +0300)
committerTimo Sirainen <tss@iki.fi>
Sun, 2 May 2004 12:57:29 +0000 (15:57 +0300)
--HG--
branch : HEAD

src/lib-index/mail-transaction-log-view.c
src/lib-index/mail-transaction-log.c

index b91c1b3dcff880909bc9770a0fae24a910a59d9b..2ae861b5afe06e368e02a7c12b64f004e0ad0c84 100644 (file)
@@ -84,8 +84,6 @@ mail_transaction_log_view_set(struct mail_transaction_log_view *view,
 
        i_assert(view->broken);
        i_assert(min_file_seq <= max_file_seq);
-       i_assert(min_file_offset >= sizeof(struct mail_transaction_log_header));
-       i_assert(max_file_offset >= sizeof(struct mail_transaction_log_header));
 
        if (view->log == NULL)
                return -1;
@@ -118,6 +116,14 @@ mail_transaction_log_view_set(struct mail_transaction_log_view *view,
                        max_file_offset = min_file_offset;
                }
        }
+
+       /* check these later than others as index file may have corrupted
+          log_file_offset. we should have recreated the log file and
+          skipped min_file_seq file above.. max_file_offset can be broken
+          only if min_file_seq = max_file_seq. */
+       i_assert(min_file_offset >= sizeof(struct mail_transaction_log_header));
+       i_assert(max_file_offset >= sizeof(struct mail_transaction_log_header));
+
        end_offset = min_file_seq == max_file_seq ?
                max_file_offset : (uoff_t)-1;
        ret = mail_transaction_log_file_map(file, min_file_offset, end_offset);
index 5f34130fa4ad4131533148643969c0a2d6af7315..11c78199bd4153a419208df42c4e27ea7a4d4125 100644 (file)
@@ -62,10 +62,11 @@ mail_transaction_log_file_set_corrupted(struct mail_transaction_log_file *file,
 }
 
 #define INDEX_HAS_MISSING_LOGS(index, file) \
-       ((file)->hdr.file_seq != (index)->hdr->log_file_seq && \
-        ((file)->hdr.prev_file_seq != (index)->hdr->log_file_seq || \
-         (file)->hdr.prev_file_offset != (index)->hdr->log_file_offset))
-
+       !(((file)->hdr.file_seq == (index)->hdr->log_file_seq && \
+          (index)->hdr->log_file_offset >= \
+          sizeof(struct mail_transaction_log_header)) || \
+         ((file)->hdr.prev_file_seq == (index)->hdr->log_file_seq && \
+          (file)->hdr.prev_file_offset == (index)->hdr->log_file_offset))
 
 static int mail_transaction_log_check_file_seq(struct mail_transaction_log *log)
 {