Mercurial > dovecot > original-hg > dovecot-1.2
changeset 6646:f3ca0b9e3628 HEAD
Fixed a race condition causing cache corruption when creating/compressing
cache file.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 28 Oct 2007 14:31:13 +0200 |
parents | ce7f9d33d566 |
children | 6dd5df1c1ec9 |
files | src/lib-index/mail-cache-transaction.c |
diffstat | 1 files changed, 14 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-cache-transaction.c Sun Oct 28 13:27:46 2007 +0200 +++ b/src/lib-index/mail-cache-transaction.c Sun Oct 28 14:31:13 2007 +0200 @@ -74,7 +74,7 @@ mail_index_ext_set_reset_id(ctx->trans, ctx->cache->ext_id, ctx->cache_file_seq); - if (ctx->cache_data) + if (ctx->cache_data != NULL) buffer_set_used_size(ctx->cache_data, 0); if (array_is_created(&ctx->cache_data_seq)) array_clear(&ctx->cache_data_seq); @@ -116,8 +116,11 @@ if (ctx->cache_file_seq == 0) { if (!ctx->cache->opened) (void)mail_cache_open_and_verify(ctx->cache); - if (!MAIL_CACHE_IS_UNUSABLE(ctx->cache)) + if (!MAIL_CACHE_IS_UNUSABLE(ctx->cache)) { + i_assert(ctx->cache_data == NULL || + ctx->cache_data->used == 0); ctx->cache_file_seq = ctx->cache->hdr->file_seq; + } } if ((ret = mail_cache_lock(ctx->cache, FALSE)) <= 0) @@ -507,15 +510,6 @@ buffer_set_used_size(ctx->cache_data, ctx->prev_pos); } - if (ctx->cache_file_seq == 0) { - if (!ctx->cache->opened) - (void)mail_cache_open_and_verify(ctx->cache); - if (MAIL_CACHE_IS_UNUSABLE(ctx->cache)) - return -1; - - ctx->cache_file_seq = ctx->cache->hdr->file_seq; - } - if (ctx->cache_file_seq != ctx->cache->hdr->file_seq) { /* cache file reopened - need to abort */ mail_cache_transaction_reset(ctx); @@ -788,6 +782,15 @@ (MAIL_CACHE_DECISION_NO | MAIL_CACHE_DECISION_FORCED)) return; + if (ctx->cache_file_seq == 0) { + if (!ctx->cache->opened) + (void)mail_cache_open_and_verify(ctx->cache); + if (MAIL_CACHE_IS_UNUSABLE(ctx->cache)) + return; + + ctx->cache_file_seq = ctx->cache->hdr->file_seq; + } + file_field = ctx->cache->field_file_map[field_idx]; if (file_field == (uint32_t)-1) { /* we'll have to add this field to headers */