diff options
author | Sanju Rakonde <srakonde@redhat.com> | 2018-09-23 16:42:54 +0530 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2018-10-01 08:02:27 +0000 |
commit | f054b511057ada37790bfb518c70d6631ed11d93 (patch) | |
tree | 742e05b9273bcc6b920a5aa7cabdf5542580e13d /cli/src/cli-cmd-parser.c | |
parent | 1c0facf59a85b1256a52e7a99b30743283a4c9cf (diff) |
cli: handle negative scenarios
When control flow reaches negative case code block, we added
"goto out" statement without assigning ret to -1.
This patch assigns return value to -1, before going to the lable "out".
Change-Id: I6db651a3c9ca285ade9ee1ca23d0abe6b36fda3a
updates: bz#1193929
Signed-off-by: Sanju Rakonde <srakonde@redhat.com>
Diffstat (limited to 'cli/src/cli-cmd-parser.c')
-rw-r--r-- | cli/src/cli-cmd-parser.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c index 3f9056b5d9e..ceb95af785d 100644 --- a/cli/src/cli-cmd-parser.c +++ b/cli/src/cli-cmd-parser.c @@ -1483,6 +1483,8 @@ cli_add_key_group_value(dict_t *dict, const char *name, const char *value, } data = gf_strdup(value); if (data == NULL) { + gf_log(THIS->name, GF_LOG_ERROR, "Failed to allocate memory for data"); + ret = -1; goto out; } @@ -3080,8 +3082,10 @@ cli_cmd_gsync_set_parse(const char **words, int wordcount, dict_t **options) cmdi++; } - if (type != GF_GSYNC_OPTION_TYPE_CONFIG && (cmdi < wordcount - 1 || glob)) + if (type != GF_GSYNC_OPTION_TYPE_CONFIG && (cmdi < wordcount - 1 || glob)) { + ret = -1; goto out; + } /* If got so far, input is valid, assemble the message */ @@ -3162,11 +3166,15 @@ cli_cmd_volume_profile_parse(const char **words, int wordcount, goto out; } - if ((strcmp(w, "start") == 0 || strcmp(w, "stop") == 0) && wordcount > 5) + if ((strcmp(w, "start") == 0 || strcmp(w, "stop") == 0) && wordcount > 5) { + ret = -1; goto out; + } - if (strcmp(w, "info") == 0 && wordcount > 7) + if (strcmp(w, "info") == 0 && wordcount > 7) { + ret = -1; goto out; + } if (strcmp(w, "start") == 0) { op = GF_CLI_STATS_START; @@ -3965,8 +3973,11 @@ cli_cmd_volume_heal_options_parse(const char **words, int wordcount, gf_xl_afr_op_t op = GF_SHD_OP_INVALID; dict = dict_new(); - if (!dict) + if (!dict) { + gf_log(THIS->name, GF_LOG_ERROR, "Failed to create the dict"); + ret = -1; goto out; + } ret = dict_set_str(dict, "volname", (char *)words[2]); if (ret) { @@ -5591,6 +5602,7 @@ cli_cmd_snapshot_parse(const char **words, int wordcount, dict_t **options, break; default: + ret = -1; gf_log("", GF_LOG_ERROR, "Opword Mismatch"); goto out; } |