From c136024613c697fec87aaff3a070862b92c57977 Mon Sep 17 00:00:00 2001 From: Atin Mukherjee Date: Wed, 26 Jul 2017 12:46:42 +0530 Subject: cli: error out incomplete CLI commands cli_cmd_bricks_parse () & cli_cmd_volume_remove_brick_parse () were not handling the the error cases where the command is incomplete with missing brick details which could lead to glusterd crashes. Credit : george.lian@nokia.com Change-Id: Ia6303457a2aa279465aa75d4e1cfcc948893d5de BUG: 1396327 Signed-off-by: Atin Mukherjee Reviewed-on: https://review.gluster.org/17870 Smoke: Gluster Build System CentOS-regression: Gluster Build System Reviewed-by: Jeff Darcy --- cli/src/cli-cmd-parser.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'cli/src/cli-cmd-parser.c') diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 7d6fd3c28d0..984ce5bbad0 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -1759,7 +1759,11 @@ parse_bricks: &brick_count); if (ret) goto out; - + if (!brick_count) { + cli_err ("No bricks specified"); + ret = -1; + goto out; + } ret = dict_set_dynstr (dict, "bricks", bricks); if (ret) goto out; @@ -1932,14 +1936,15 @@ out: int32_t cli_cmd_volume_remove_brick_parse (const char **words, int wordcount, - dict_t **options, int *question) + dict_t **options, int *question, + int *brick_count) { dict_t *dict = NULL; char *volname = NULL; char *delimiter = NULL; int ret = -1; char key[50]; - int brick_count = 0, brick_index = 0; + int brick_index = 0; int32_t tmp_index = 0; int32_t j = 0; char *tmp_brick = NULL; @@ -2072,7 +2077,7 @@ cli_cmd_volume_remove_brick_parse (const char **words, int wordcount, } j++; } - snprintf (key, 50, "brick%d", ++brick_count); + snprintf (key, 50, "brick%d", ++(*brick_count)); ret = dict_set_str (dict, key, (char *)words[brick_index++]); if (ret) @@ -2080,7 +2085,7 @@ cli_cmd_volume_remove_brick_parse (const char **words, int wordcount, } if (command != GF_OP_CMD_STATUS && command != GF_OP_CMD_STOP) { - ret = dict_set_int32 (dict, "count", brick_count); + ret = dict_set_int32 (dict, "count", *brick_count); if (ret) goto out; } -- cgit