[sheepdog] [PATCH v2 3/3] sheep: add check to avoid accessing array out of range

Robin Dong robin.k.dong at gmail.com
Thu Dec 5 04:46:00 CET 2013


From: Robin Dong <sanbai at taobao.com>

If we use 4:2 as copy_policy and there are 6 nodes in cluster, everything is ok.
But after one node crash, the target_nodes[] will contain just 5 elements, when
gateway_forward_request() access the target_nodes[] with max index 'nr_to_send'
(which is 6), it will cause problem.

Signed-off-by: Robin Dong <sanbai at taobao.com>
---
 sheep/gateway.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/sheep/gateway.c b/sheep/gateway.c
index 3565619..f0cb514 100644
--- a/sheep/gateway.c
+++ b/sheep/gateway.c
@@ -510,6 +510,13 @@ static int gateway_forward_request(struct request *req)
 	if (!reqs)
 		return SD_RES_NETWORK_ERROR;
 
+	/* avoid out range of target_nodes[] */
+	if (nr_to_send > nr_copies) {
+		sd_err("There isn't enough copies(%d) to send out (%d)",
+		       nr_copies, nr_to_send);
+		return SD_RES_SYSTEM_ERROR;
+	}
+
 	for (i = 0; i < nr_to_send; i++) {
 		struct sockfd *sfd;
 		const struct node_id *nid;
-- 
1.7.12.4




More information about the sheepdog mailing list