diff options
author | Pranith Kumar K <pranithk@gluster.com> | 2010-08-25 01:59:15 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2010-08-25 02:08:47 -0700 |
commit | 606cf3e291029169ec8154dec52c9b5ec6afc455 (patch) | |
tree | f8ede82fab9538e6bba201b8e966f169012b33b9 /cli | |
parent | a0c874f09e294ec75a18a5436bd01eaa97f22f81 (diff) |
cli: check if the arguments are present before accessing
Signed-off-by: Pranith Kumar K <pranithk@gluster.com>
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 1431 (cli: check if arguments exist before the accessing them)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1431
Diffstat (limited to 'cli')
-rw-r--r-- | cli/src/cli-cmd-parser.c | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 09c9ee0e550..f914e4e522e 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); |