From 0590678d05473d40c8107be8cf5a66879f9d196f Mon Sep 17 00:00:00 2001 From: Sunny Kumar Date: Thu, 30 Aug 2018 16:09:04 +0530 Subject: cli : fix coverity issue in cli-cmd-parser.c This patch fixes 1175017 and 1382401. This patch fixes resource leak by validating brick_count is valid or not. If brick_count is not valid we are coming out in "cli_cmd_bricks_parse" without allocating memory to "brick_str" which is eventually pointed by bricks. Change-Id: I8ed0f29495379ec49484c5c4069865db3653506f updates: bz#789278 Signed-off-by: Sunny Kumar --- cli/src/cli-cmd-parser.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'cli/src') diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index bd876bdb742..d0f8a20cee0 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -172,6 +172,13 @@ cli_cmd_bricks_parse (const char **words, int wordcount, int brick_index, ++brick_index; } + /* If brick count is not valid exit here */ + if (!*brick_count) { + cli_err ("No bricks specified"); + ret = -1; + goto out; + } + brick_list_len++; /* For terminating null char */ bricks_str = GF_MALLOC(brick_list_len, gf_common_mt_char); @@ -712,14 +719,6 @@ cli_cmd_volume_create_parse (struct cli_state *state, const char **words, if (ret) goto out; - /* If brick-count is not valid when replica or stripe is - given, exit here */ - if (!brick_count) { - cli_err ("No bricks specified"); - ret = -1; - goto out; - } - if (type == GF_CLUSTER_TYPE_DISPERSE) { ret = cli_cmd_create_disperse_check (state, &disperse_count, &redundancy_count, @@ -1821,11 +1820,7 @@ 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; -- cgit