[sheepdog] [PATCH] sheep: check the return value of epoch_log_read_with_timestamp() correctly

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Tue May 21 09:18:35 CEST 2013


log->nr_nodes is an unsigned integer, so we cannot use it for
assigning the negative value.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 sheep/ops.c | 21 +++++++++++++--------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/sheep/ops.c b/sheep/ops.c
index 9399fd8..61e6743 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -436,6 +436,8 @@ static int local_stat_cluster(struct request *req)
 	max_logs = req->rq.data_length / sizeof(*log);
 	epoch = get_latest_epoch();
 	for (i = 0; i < max_logs; i++) {
+		size_t nr_nodes;
+
 		if (epoch <= 0)
 			break;
 
@@ -443,14 +445,17 @@ static int local_stat_cluster(struct request *req)
 		memset(log, 0, sizeof(*log));
 		log->epoch = epoch;
 		log->ctime = get_cluster_ctime();
-		log->nr_nodes = epoch_log_read_with_timestamp(epoch, log->nodes,
-							sizeof(log->nodes),
-							(time_t *)&log->time);
-		if (log->nr_nodes == -1)
-			log->nr_nodes = epoch_log_read_remote(epoch, log->nodes,
-							sizeof(log->nodes),
-							(time_t *)&log->time,
-							req->vinfo);
+		nr_nodes = epoch_log_read_with_timestamp(epoch, log->nodes,
+							 sizeof(log->nodes),
+							 (time_t *)&log->time);
+		if (nr_nodes == -1)
+			nr_nodes = epoch_log_read_remote(epoch, log->nodes,
+							 sizeof(log->nodes),
+							 (time_t *)&log->time,
+							 req->vinfo);
+		assert(nr_nodes >= 0);
+		assert(nr_nodes <= SD_MAX_NODES);
+		log->nr_nodes = nr_nodes;
 
 		log->disable_recovery = sys->disable_recovery;
 
-- 
1.8.1.3.566.gaa39828




More information about the sheepdog mailing list