]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Fix using old map when checking for unexpected changes during log rotate
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 8 Jul 2019 15:59:21 +0000 (18:59 +0300)
committerTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 8 Jul 2019 17:01:20 +0000 (20:01 +0300)
This shouldn't normally be possible. The log is locked, so other processes
shouldn't be able to write anything to it. This was mainly found by the
earlier bug.

src/lib-index/mail-index-write.c

index f427734c2786124764228cd6e1b38225998170e3..0c3bfcdd54a72cc7664366a9e8a6c30d8463afa0 100644 (file)
@@ -118,8 +118,7 @@ static int mail_index_recreate(struct mail_index *index)
 
 void mail_index_write(struct mail_index *index, bool want_rotate)
 {
-       struct mail_index_map *map = index->map;
-       struct mail_index_header *hdr = &map->hdr;
+       struct mail_index_header *hdr = &index->map->hdr;
 
        i_assert(index->log_sync_locked);
 
@@ -134,6 +133,12 @@ void mail_index_write(struct mail_index *index, bool want_rotate)
                if (mail_transaction_log_rotate(index->log, FALSE) == 0) {
                        struct mail_transaction_log_file *file =
                                index->log->head;
+                       /* Log rotation refreshes the index, which may cause the
+                          map to change. Because we're locked, it's not
+                          supposed to happen and will likely lead to an
+                          assert-crash below, but we still need to make sure
+                          we're using the latest map to do the checks. */
+                       hdr = &index->map->hdr;
                        i_assert(file->hdr.prev_file_seq == hdr->log_file_seq);
                        i_assert(file->hdr.prev_file_offset == hdr->log_file_head_offset);
                        hdr->log_file_seq = file->hdr.file_seq;