diff options
author | Pranith Kumar K <pranithk@gluster.com> | 2010-08-25 01:29:07 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2010-08-25 00:41:48 -0700 |
commit | 29a9b190148ac7f2bf83e381a9e8024b164904b6 (patch) | |
tree | e3c0ca48fb6baac4e2a886e2249bb941e3c4072a /cli | |
parent | 89e6c3ee0a031eec5090fe2396678769e08fb01f (diff) |
cli: validating if the arguments exist before accessing in volume create
Signed-off-by: Pranith Kumar K <pranithk@gluster.com>
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
BUG: 1202 ()
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=1202
Diffstat (limited to 'cli')
-rw-r--r-- | cli/src/cli-cmd-parser.c | 15 | ||||
-rw-r--r-- | cli/src/cli-cmd-volume.c | 10 |
2 files changed, 22 insertions, 3 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index e2c802130..09c9ee0e5 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -60,6 +60,9 @@ cli_cmd_volume_create_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); @@ -88,8 +91,16 @@ cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options 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); if (!count) { /* Wrong number of replica count */ @@ -106,6 +117,10 @@ cli_cmd_volume_create_parse (const char **words, int wordcount, dict_t **options 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); if (!count) { /* Wrong number of stripe count */ diff --git a/cli/src/cli-cmd-volume.c b/cli/src/cli-cmd-volume.c index 0dfc2af91..fddcc213f 100644 --- a/cli/src/cli-cmd-volume.c +++ b/cli/src/cli-cmd-volume.c @@ -85,8 +85,10 @@ cli_cmd_volume_create_cbk (struct cli_state *state, struct cli_cmd_word *word, ret = cli_cmd_volume_create_parse (words, wordcount, &options); - if (ret) + if (ret) { + cli_out ("Command Parsing Failed"); goto out; + } if (proc->fn) { ret = proc->fn (frame, THIS, options); @@ -94,8 +96,10 @@ cli_cmd_volume_create_cbk (struct cli_state *state, struct cli_cmd_word *word, out: if (ret) { - char *volname = (char *) words[2]; - cli_out ("Creating Volume %s failed",volname ); + if (wordcount > 2) { + char *volname = (char *) words[2]; + cli_out ("Creating Volume %s failed",volname ); + } } if (options) dict_destroy (options); |