]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Fix resizing of statfiles.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 5 Dec 2013 12:40:01 +0000 (12:40 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 5 Dec 2013 12:40:01 +0000 (12:40 +0000)
src/statfile.c

index 9cc2d58f36eba1eba43647ae83973fb1c1fbf134..b4771ce15ed3578417c0bc7aee68a1410f62b7bb 100644 (file)
@@ -235,7 +235,7 @@ statfile_pool_reindex (statfile_pool_t * pool, gchar *filename, size_t old_size,
        }
 
        pos = map + (sizeof (struct stat_file) - sizeof (struct stat_file_block));
-       while (pos - map < (gint)old_size) {
+       while (old_size - (pos - map) >= sizeof (block)) {
                block = (struct stat_file_block *)pos;
                if (block->hash1 != 0 && block->value != 0) {
                        statfile_pool_set_block_common (pool, new, block->hash1, block->hash2, 0, block->value, FALSE);
@@ -307,7 +307,8 @@ statfile_pool_open (statfile_pool_t * pool, gchar *filename, size_t size, gboole
        }
 
        memory_pool_lock_mutex (pool->lock);
-       if (!forced && size != (size_t)st.st_size && size > sizeof (struct stat_file)) {
+       if (!forced && labs (size - st.st_size) > (long)sizeof (struct stat_file) * 2
+                       && size > sizeof (struct stat_file)) {
                memory_pool_unlock_mutex (pool->lock);
                msg_warn ("need to reindex statfile old size: %Hz, new size: %Hz", st.st_size, size);
                return statfile_pool_reindex (pool, filename, st.st_size, size);