From 3ea02e2519e2a5304a3af30a04f57c9cec8de0c7 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 24 Oct 2005 18:40:13 +0000 Subject: [PATCH] (ef_open): Fail if file size is not a multiple of record size. --- src/lib/common/file.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lib/common/file.c b/src/lib/common/file.c index e86eda4e..e99d74e8 100644 --- a/src/lib/common/file.c +++ b/src/lib/common/file.c @@ -58,7 +58,7 @@ int ef_open(int type, int how) { struct empfile *ep; - int oflags, size; + int oflags, fsiz, size; if (ef_check(type) < 0) return 0; @@ -82,7 +82,14 @@ ef_open(int type, int how) ep->baseid = 0; ep->cids = 0; ep->flags = (ep->flags & ~EFF_OPEN) | (how ^ ~EFF_CREATE); - ep->fids = fsize(ep->fd) / ep->size; + fsiz = fsize(ep->fd); + if (fsiz % ep->size) { + logerror("Can't open %s (file size not a multiple of record size %d)", + ep->file, ep->size); + close(ep->fd); + return 0; + } + ep->fids = fsiz / ep->size; if (ep->flags & EFF_MEM) ep->csize = ep->fids; else