]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Make sure an already-corrupted index/log isn't written
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 17 Nov 2016 15:13:09 +0000 (17:13 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 18 Nov 2016 11:55:48 +0000 (13:55 +0200)
src/lib-index/mail-index-write.c
src/lib-index/mail-transaction-log-file.c

index 0c59cec40d2878085ffd11fb5d53b63495a8aada..57f4e85e73a9717d8950374fc7abd52a5be80268 100644 (file)
@@ -67,6 +67,8 @@ static int mail_index_recreate(struct mail_index *index)
 
        i_assert(!MAIL_INDEX_IS_IN_MEMORY(index));
        i_assert(map->hdr.indexid == index->indexid);
+       i_assert((map->hdr.flags & MAIL_INDEX_HDR_FLAG_CORRUPTED) == 0);
+       i_assert(index->indexid != 0);
 
        fd = mail_index_create_tmp_file(index, index->filepath, &path);
        if (fd == -1)
index 302d6c3b2fe21088d5ae5f9bde6d985bada7001f..36d519b0bbb3e6a09dde64990e931591bade8897 100644 (file)
@@ -220,6 +220,8 @@ mail_transaction_log_init_hdr(struct mail_transaction_log *log,
        struct mail_index *index = log->index;
        struct mail_transaction_log_file *file;
 
+       i_assert(index->indexid != 0);
+
        memset(hdr, 0, sizeof(*hdr));
        hdr->major_version = MAIL_TRANSACTION_LOG_MAJOR_VERSION;
        hdr->minor_version = MAIL_TRANSACTION_LOG_MINOR_VERSION;
@@ -846,6 +848,13 @@ int mail_transaction_log_file_create(struct mail_transaction_log_file *file,
                return -1;
        }
 
+       if (index->indexid == 0) {
+               mail_index_set_error(index,
+                       "Can't create log file %s: Index is marked corrupted",
+                       file->filepath);
+               return -1;
+       }
+
        mail_transaction_log_get_dotlock_set(file->log, &new_dotlock_set);
        new_dotlock_set.lock_suffix = LOG_NEW_DOTLOCK_SUFFIX;