Skip to content

Commit

Permalink
lib-index: After MAIL_INDEX_OPEN_FLAG_SAVEONLY access cache's read_bu…
Browse files Browse the repository at this point in the history
…f wasn't always reset.

This could have caused at least errors like:

Corrupted index cache file .../dovecot.index.cache: File too small

I'm not sure if it might have also returned stale data sometimes.

Easy way to reproduce this bug was:
imaptest copy=100 copybox=Trash &
imaptest box=Trash append=0
  • Loading branch information
sirainen committed Mar 2, 2016
1 parent d6d9ee1 commit 5bd1c1d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/lib-index/mail-cache.c
Expand Up @@ -60,6 +60,8 @@ void mail_cache_file_close(struct mail_cache *cache)

if (cache->file_cache != NULL)
file_cache_set_fd(cache->file_cache, -1);
if (cache->read_buf != NULL)
buffer_set_used_size(cache->read_buf, 0);

cache->mmap_base = NULL;
cache->hdr = NULL;
Expand Down Expand Up @@ -465,6 +467,8 @@ int mail_cache_map(struct mail_cache *cache, size_t offset, size_t size,
/* map the whole file */
cache->hdr = NULL;
cache->mmap_length = 0;
if (cache->read_buf != NULL)
buffer_set_used_size(cache->read_buf, 0);

cache->mmap_base = mmap_ro_file(cache->fd, &cache->mmap_length);
if (cache->mmap_base == MAP_FAILED) {
Expand Down

0 comments on commit 5bd1c1d

Please sign in to comment.