From: Timo Sirainen Date: Mon, 8 Jul 2019 15:59:21 +0000 (+0300) Subject: lib-index: Fix using old map when checking for unexpected changes during log rotate X-Git-Tag: 2.3.9~406 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ea6dafcffd68a8c1d3d43a4c0e25fdf61bfae54e;p=thirdparty%2Fdovecot%2Fcore.git lib-index: Fix using old map when checking for unexpected changes during log rotate 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. --- diff --git a/src/lib-index/mail-index-write.c b/src/lib-index/mail-index-write.c index f427734c27..0c3bfcdd54 100644 --- a/src/lib-index/mail-index-write.c +++ b/src/lib-index/mail-index-write.c @@ -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;