[sheepdog] [PATCH] sheep: detect invalid response code in sd_strerror()

Hitoshi Mitake mitake.hitoshi at lab.ntt.co.jp
Thu Aug 22 09:10:02 CEST 2013


Commit a4d01de did wrong treatment of data structure of request. And
it caused segfault in sd_strerror() because of wrong index of the desc
array. This patch let the function catch such a bug and return string
representation of unknown response code.

Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
 include/sheep.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/sheep.h b/include/sheep.h
index 1d146bd..68c852f 100644
--- a/include/sheep.h
+++ b/include/sheep.h
@@ -242,7 +242,7 @@ static inline const char *sd_strerror(int err)
 		[SD_RES_CLUSTER_ERROR] = "Cluster driver error",
 	};
 
-	if (descs[err] == NULL) {
+	if (!(0 <= err && err < ARRAY_SIZE(descs)) || descs[err] == NULL) {
 		static __thread char msg[32];
 		snprintf(msg, sizeof(msg), "Invalid error code %x", err);
 		return msg;
-- 
1.7.10.4




More information about the sheepdog mailing list