aboutsummaryrefslogtreecommitdiffstats
path: root/src/statfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/statfile.c')
-rw-r--r--src/statfile.c12
1 files changed, 12 insertions, 0 deletions
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;