[rrd-developers] [PATCH] rrd_open: Make sure the data portion of the file is big enough
kevin brintnall
kbrint at rufus.net
Fri Oct 3 22:02:14 CEST 2008
After we read the header, we can determine how large the entire file
should be. Make sure that the file is large enough.
---
src/rrd_open.c | 25 ++++++++++++++++++++++++-
1 files changed, 24 insertions(+), 1 deletions(-)
diff --git a/src/rrd_open.c b/src/rrd_open.c
index 7a85aa8..2796506 100644
--- a/src/rrd_open.c
+++ b/src/rrd_open.c
@@ -72,7 +72,7 @@ rrd_file_t *rrd_open(
#ifdef HAVE_MMAP
ssize_t _page_size = sysconf(_SC_PAGESIZE);
int mm_prot = PROT_READ, mm_flags = 0;
- char *data;
+ char *data = MAP_FAILED;
#endif
off_t offset = 0;
struct stat statb;
@@ -271,11 +271,34 @@ rrd_file_t *rrd_open(
rrd_file->header_len = offset;
rrd_file->pos = offset;
+
+ {
+ unsigned long row_cnt = 0;
+ unsigned long i;
+
+ for (i=0; i<rrd->stat_head->rra_cnt; i++)
+ row_cnt += rrd->rra_def[i].row_cnt;
+
+ off_t correct_len = rrd_file->header_len +
+ sizeof(rrd_value_t) * row_cnt * rrd->stat_head->ds_cnt;
+
+ if (correct_len > rrd_file->file_len)
+ {
+ rrd_set_error("'%s' is too small (should be %ld bytes)",
+ file_name, (long long) correct_len);
+ goto out_nullify_head;
+ }
+ }
+
out_done:
return (rrd_file);
out_nullify_head:
rrd->stat_head = NULL;
out_close:
+#ifdef HAVE_MMAP
+ if (data != MAP_FAILED)
+ munmap(data, rrd_file->file_len);
+#endif
close(rrd_file->fd);
out_free:
free(rrd_file);
--
1.6.0.2
More information about the rrd-developers
mailing list