[sheepdog] [PATCH] sheep/store: add epoch file length checking

Ruoyu liangry at ucweb.com
Thu Jul 10 04:51:05 CEST 2014


If epoch file length is shorter than size of time due to file broken,
epoch_stat.st_size - sizeof(*timestamp) is negative. However,
the third parameter of function xread will get it as type size_t,
then xread will think there are many data to be read. Therefore,
a file length checking to prevent this situation is needed.

Signed-off-by: Ruoyu <liangry at ucweb.com>
---
 sheep/store.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/sheep/store.c b/sheep/store.c
index 87913d4..befcd13 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -71,6 +71,11 @@ static int do_epoch_log_read(uint32_t epoch, struct sd_node *nodes, int len,
 		goto err;
 	}
 
+	if (epoch_stat.st_size < sizeof(*timestamp)) {
+		sd_err("invalid epoch %"PRIu32" log", epoch);
+		goto err;
+	}
+
 	if (len < epoch_stat.st_size - sizeof(*timestamp)) {
 		close(fd);
 		return -2;
-- 
1.8.3.2





More information about the sheepdog mailing list