From: Vsevolod Stakhov Date: Fri, 15 Nov 2013 15:07:24 +0000 (+0000) Subject: Do not create too small statfiles. X-Git-Tag: 0.6.0~65 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4cd82b05a91ce79c3c84845189311c844ff587b4;p=rspamd.git Do not create too small statfiles. --- diff --git a/src/statfile.c b/src/statfile.c index 560a06def..c2ca57213 100644 --- a/src/statfile.c +++ b/src/statfile.c @@ -229,6 +229,12 @@ statfile_pool_reindex (statfile_pool_t * pool, gchar *filename, size_t old_size, struct stat_file_block *block; struct stat_file_header *header; + if (size < + sizeof (struct stat_file_header) + sizeof (struct stat_file_section) + sizeof (block)) { + msg_err ("file %s is too small to carry any statistic: %z", filename, size); + return NULL; + } + /* First of all rename old file */ memory_pool_lock_mutex (pool->lock); @@ -464,6 +470,12 @@ statfile_pool_create (statfile_pool_t * pool, gchar *filename, size_t size) return 0; } + if (size < + sizeof (struct stat_file_header) + sizeof (struct stat_file_section) + sizeof (block)) { + msg_err ("file %s is too small to carry any statistic: %z", filename, size); + return -1; + } + memory_pool_lock_mutex (pool->lock); nblocks = (size - sizeof (struct stat_file_header) - sizeof (struct stat_file_section)) / sizeof (struct stat_file_block); header.total_blocks = nblocks;