summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSunny Kumar <sunkumar@redhat.com>2018-08-30 16:09:04 +0530
committerAtin Mukherjee <amukherj@redhat.com>2018-09-05 04:42:09 +0000
commit0590678d05473d40c8107be8cf5a66879f9d196f (patch)
treedc2fc456272fafa35622f3aa98fdf080a59c21a5
parent33128ef59a05f2c31c0f51919c5dd7746cebd6ef (diff)
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 <sunkumar@redhat.com>
-rw-r--r--cli/src/cli-cmd-parser.c21
1 files changed, 8 insertions, 13 deletions
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;