From 606cf3e291029169ec8154dec52c9b5ec6afc455 Mon Sep 17 00:00:00 2001 From: Pranith Kumar K Date: Wed, 25 Aug 2010 01:59:15 +0000 Subject: cli: check if the arguments are present before accessing Signed-off-by: Pranith Kumar K Signed-off-by: Anand V. Avati BUG: 1431 (cli: check if arguments exist before the accessing them) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1431 --- cli/src/cli-cmd-parser.c | 62 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 3 deletions(-) (limited to 'cli') diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 09c9ee0e5..f914e4e52 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -225,6 +225,9 @@ cli_cmd_volume_set_parse (const char **words, int wordcount, dict_t **options) if (!dict) goto out; + if (wordcount < 3) + goto out; + volname = (char *)words[2]; GF_ASSERT (volname); @@ -296,6 +299,9 @@ cli_cmd_volume_add_brick_parse (const char **words, int wordcount, if (!dict) goto out; + if (wordcount < 3) + goto out; + volname = (char *)words[2]; GF_ASSERT (volname); @@ -305,12 +311,27 @@ cli_cmd_volume_add_brick_parse (const char **words, int wordcount, if (ret) goto out; + if (wordcount < 4) { + ret = -1; + goto out; + } + if ((strcasecmp (words[3], "replica")) == 0) { type = GF_CLUSTER_TYPE_REPLICATE; + if (wordcount < 5) { + ret = -1; + goto out; + } + count = strtol (words[4], NULL, 0); brick_index = 5; } else if ((strcasecmp (words[3], "stripe")) == 0) { type = GF_CLUSTER_TYPE_STRIPE; + if (wordcount < 5) { + ret = -1; + goto out; + } + count = strtol (words[4], NULL, 0); brick_index = 5; } else { @@ -393,6 +414,9 @@ cli_cmd_volume_remove_brick_parse (const char **words, int wordcount, if (!dict) goto out; + if (wordcount < 3) + goto out; + volname = (char *)words[2]; GF_ASSERT (volname); @@ -402,12 +426,27 @@ cli_cmd_volume_remove_brick_parse (const char **words, int wordcount, if (ret) goto out; + if (wordcount < 4) { + ret = -1; + goto out; + } + if ((strcasecmp (words[3], "replica")) == 0) { type = GF_CLUSTER_TYPE_REPLICATE; + if (wordcount < 5) { + ret = -1; + goto out; + } + count = strtol (words[4], NULL, 0); brick_index = 5; } else if ((strcasecmp (words[3], "stripe")) == 0) { type = GF_CLUSTER_TYPE_STRIPE; + if (wordcount < 5) { + ret = -1; + goto out; + } + count = strtol (words[4], NULL, 0); brick_index = 5; } else { @@ -469,6 +508,9 @@ cli_cmd_volume_replace_brick_parse (const char **words, int wordcount, if (!dict) goto out; + if (wordcount < 3) + goto out; + volname = (char *)words[2]; GF_ASSERT (volname); @@ -478,13 +520,21 @@ cli_cmd_volume_replace_brick_parse (const char **words, int wordcount, if (ret) goto out; + if (wordcount < 4) { + ret = -1; + goto out; + } + if (strchr ((char *)words[3], ':')) { ret = dict_set_str (dict, "src-brick", (char *)words[3]); if (ret) goto out; - GF_ASSERT (words[4]); + if (wordcount < 5) { + ret = -1; + goto out; + } ret = dict_set_str (dict, "dst-brick", (char *)words[4]); @@ -496,7 +546,10 @@ cli_cmd_volume_replace_brick_parse (const char **words, int wordcount, op_index = 3; } - GF_ASSERT (words[op_index]); + if (wordcount < (op_index + 1)) { + ret = -1; + goto out; + } op = (char *) words[op_index]; @@ -512,7 +565,10 @@ cli_cmd_volume_replace_brick_parse (const char **words, int wordcount, replace_op = GF_REPLACE_OP_STATUS; } - GF_ASSERT (replace_op != GF_REPLACE_OP_NONE); + if (replace_op == GF_REPLACE_OP_NONE) { + ret = -1; + goto out; + } ret = dict_set_int32 (dict, "operation", (int32_t) replace_op); -- cgit