]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: After MAIL_INDEX_OPEN_FLAG_SAVEONLY access cache's read_buf wasn't always...
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 2 Mar 2016 22:15:30 +0000 (00:15 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Wed, 2 Mar 2016 22:19:30 +0000 (00:19 +0200)
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

src/lib-index/mail-cache.c

index 4f6e43fd686923c673c9453aa4bda0e4d4c288d8..34c05c5d84babd67cdc2064413a4c727e5403917 100644 (file)
@@ -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;
@@ -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) {