Skip to content

Commit

Permalink
lib-index: Fix potential crash after resetting index
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
sirainen committed Oct 23, 2024
1 parent 735f140 commit f8ad6b6
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/lib-index/mail-index-transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit f8ad6b6

Please sign in to comment.