From: Timo Sirainen Date: Wed, 23 Oct 2024 07:42:35 +0000 (+0300) Subject: lib-index: Fix potential crash after resetting index X-Git-Tag: 2.4.0~1431 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f8ad6b6f37da27bf51d37e8a3d6883a9cdaaa75a;p=thirdparty%2Fdovecot%2Fcore.git lib-index: Fix potential crash after resetting index The log's sync_offset wasn't updated after the reset if there were no other changes. This ended up in a broken state in mail_transaction_log_append_locked() where it thought there was garbage at the end of the transaction log, and crashed trying to truncate it. --- diff --git a/src/lib-index/mail-index-transaction.c b/src/lib-index/mail-index-transaction.c index d8245a3d9f..9a887d3220 100644 --- a/src/lib-index/mail-index-transaction.c +++ b/src/lib-index/mail-index-transaction.c @@ -152,11 +152,6 @@ mail_transaction_log_file_refresh(struct mail_index_transaction *t, transactions. */ if (mail_transaction_log_rotate(t->view->index->log, TRUE) < 0) return -1; - - if (!MAIL_INDEX_TRANSACTION_HAS_CHANGES(t)) { - /* we only wanted to reset */ - return 0; - } } file = t->view->index->log->head; @@ -166,7 +161,7 @@ mail_transaction_log_file_refresh(struct mail_index_transaction *t, i_assert(file->sync_offset >= file->buffer_offset); ctx->new_highest_modseq = file->sync_highest_modseq; - return 1; + return 0; } static int @@ -191,7 +186,7 @@ mail_index_transaction_commit_real(struct mail_index_transaction *t, if (mail_transaction_log_append_begin(log->index, trans_flags, &ctx) < 0) return -1; ret = mail_transaction_log_file_refresh(t, ctx); - if (ret > 0) T_BEGIN { + if (ret == 0) T_BEGIN { mail_index_transaction_finish(t); mail_index_transaction_export(t, ctx, changes_r); } T_END;