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>
This commit is contained in:
parent
1c0facf59a
commit
f054b51105
@ -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;
|
||||
}
|
||||
|
@ -264,8 +264,11 @@ cli_cmd_umount_cbk(struct cli_state *state, struct cli_cmd_word *word,
|
||||
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_UMOUNT];
|
||||
if (proc && proc->fn) {
|
||||
frame = create_frame(THIS, THIS->ctx->pool);
|
||||
if (!frame)
|
||||
if (!frame) {
|
||||
gf_log(THIS->name, GF_LOG_ERROR, "failed to create frame");
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
ret = proc->fn(frame, THIS, dict);
|
||||
}
|
||||
|
||||
@ -501,8 +504,11 @@ cli_cmd_sys_exec_cbk(struct cli_state *state, struct cli_cmd_word *word,
|
||||
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_SYS_EXEC];
|
||||
if (proc->fn) {
|
||||
frame = create_frame(THIS, THIS->ctx->pool);
|
||||
if (!frame)
|
||||
if (!frame) {
|
||||
gf_log(THIS->name, GF_LOG_ERROR, "failed to create frame");
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
CLI_LOCAL_INIT(local, words, frame, dict);
|
||||
ret = proc->fn(frame, THIS, (void *)dict);
|
||||
|
||||
@ -559,8 +565,11 @@ cli_cmd_copy_file_cbk(struct cli_state *state, struct cli_cmd_word *word,
|
||||
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_COPY_FILE];
|
||||
if (proc && proc->fn) {
|
||||
frame = create_frame(THIS, THIS->ctx->pool);
|
||||
if (!frame)
|
||||
if (!frame) {
|
||||
gf_log(THIS->name, GF_LOG_ERROR, "failed to create frame");
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
CLI_LOCAL_INIT(local, words, frame, dict);
|
||||
ret = proc->fn(frame, THIS, (void *)dict);
|
||||
}
|
||||
|
@ -177,8 +177,11 @@ cli_cmd_sync_volume_cbk(struct cli_state *state, struct cli_cmd_word *word,
|
||||
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_SYNC_VOLUME];
|
||||
|
||||
frame = create_frame(THIS, THIS->ctx->pool);
|
||||
if (!frame)
|
||||
if (!frame) {
|
||||
gf_log(THIS->name, GF_LOG_ERROR, "failed to create frame");
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
CLI_LOCAL_INIT(local, words, frame, dict);
|
||||
|
||||
@ -763,8 +766,11 @@ cli_cmd_volume_profile_cbk(struct cli_state *state, struct cli_cmd_word *word,
|
||||
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_PROFILE_VOLUME];
|
||||
|
||||
frame = create_frame(THIS, THIS->ctx->pool);
|
||||
if (!frame)
|
||||
if (!frame) {
|
||||
gf_log(THIS->name, GF_LOG_ERROR, "failed to create frame");
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
CLI_LOCAL_INIT(local, words, frame, options);
|
||||
|
||||
@ -960,6 +966,10 @@ cli_event_remove_brick_str(dict_t *options, char **event_str,
|
||||
|
||||
bricklist = GF_CALLOC(eventstrlen, sizeof(char), gf_common_mt_char);
|
||||
if (!bricklist) {
|
||||
gf_log(THIS->name, GF_LOG_ERROR,
|
||||
"memory allocation failed for"
|
||||
"bricklist");
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
@ -1392,8 +1402,11 @@ cli_cmd_volume_tier_cbk(struct cli_state *state, struct cli_cmd_word *word,
|
||||
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_TIER];
|
||||
|
||||
frame = create_frame(THIS, THIS->ctx->pool);
|
||||
if (!frame)
|
||||
if (!frame) {
|
||||
gf_log(THIS->name, GF_LOG_ERROR, "failed to create frame");
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
CLI_LOCAL_INIT(local, words, frame, options);
|
||||
|
||||
@ -2289,8 +2302,11 @@ cli_cmd_volume_top_cbk(struct cli_state *state, struct cli_cmd_word *word,
|
||||
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_TOP_VOLUME];
|
||||
|
||||
frame = create_frame(THIS, THIS->ctx->pool);
|
||||
if (!frame)
|
||||
if (!frame) {
|
||||
gf_log(THIS->name, GF_LOG_ERROR, "failed to create frame");
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
CLI_LOCAL_INIT(local, words, frame, options);
|
||||
|
||||
@ -2338,8 +2354,11 @@ cli_cmd_log_rotate_cbk(struct cli_state *state, struct cli_cmd_word *word,
|
||||
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_LOG_ROTATE];
|
||||
|
||||
frame = create_frame(THIS, THIS->ctx->pool);
|
||||
if (!frame)
|
||||
if (!frame) {
|
||||
gf_log(THIS->name, GF_LOG_ERROR, "failed to create frame");
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = cli_cmd_log_rotate_parse(words, wordcount, &options);
|
||||
if (ret)
|
||||
@ -2608,12 +2627,17 @@ cli_cmd_volume_status_cbk(struct cli_state *state, struct cli_cmd_word *word,
|
||||
proc = &cli_rpc_prog->proctable[GLUSTER_CLI_STATUS_ALL];
|
||||
}
|
||||
|
||||
if (!proc->fn)
|
||||
if (!proc->fn) {
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
frame = create_frame(THIS, THIS->ctx->pool);
|
||||
if (!frame)
|
||||
if (!frame) {
|
||||
gf_log(THIS->name, GF_LOG_ERROR, "failed to create frame");
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
CLI_LOCAL_INIT(local, words, frame, dict);
|
||||
|
||||
@ -3374,7 +3398,7 @@ struct cli_cmd volume_cmds[] = {
|
||||
|
||||
#if (SYNCDAEMON_COMPILE)
|
||||
{"volume " GEOREP " [<VOLNAME>] [<SLAVE-URL>] {create [[ssh-port n] "
|
||||
"[[no-verify]|[push-pem]]] [force]"
|
||||
"[[no-verify]|[push-pem]]] [force]"
|
||||
"|start [force]|stop [force]|pause [force]|resume [force]|config|status "
|
||||
"[detail]|delete [reset-sync-time]} [options...]",
|
||||
cli_cmd_volume_gsync_set_cbk, "Geo-sync operations",
|
||||
|
@ -3989,6 +3989,7 @@ cli_quotad_getlimit_cbk(struct rpc_req *req, struct iovec *iov, int count,
|
||||
if (node == NULL) {
|
||||
gf_log("cli", GF_LOG_ERROR, "failed to add node to the list");
|
||||
dict_unref(dict);
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
@ -4270,6 +4271,7 @@ gf_cli_getspec_cbk(struct rpc_req *req, struct iovec *iov, int count,
|
||||
if (rsp.op_ret == -1) {
|
||||
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
|
||||
"getspec failed");
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
@ -4278,6 +4280,7 @@ gf_cli_getspec_cbk(struct rpc_req *req, struct iovec *iov, int count,
|
||||
spec = GF_MALLOC(rsp.op_ret + 1, cli_mt_char);
|
||||
if (!spec) {
|
||||
gf_log("", GF_LOG_ERROR, "out of memory");
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
memcpy(spec, rsp.spec, rsp.op_ret);
|
||||
@ -4318,6 +4321,7 @@ gf_cli_pmap_b2p_cbk(struct rpc_req *req, struct iovec *iov, int count,
|
||||
if (rsp.op_ret == -1) {
|
||||
gf_log(((call_frame_t *)myframe)->this->name, GF_LOG_ERROR,
|
||||
"pump_b2p failed");
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
@ -4551,8 +4555,11 @@ gf_cli_get_volume(call_frame_t *frame, xlator_t *this, void *data)
|
||||
ctx = data;
|
||||
|
||||
dict = dict_new();
|
||||
if (!dict)
|
||||
if (!dict) {
|
||||
gf_log(THIS->name, GF_LOG_ERROR, "Failed to create the dict");
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (ctx->volname) {
|
||||
ret = dict_set_str(dict, "volname", ctx->volname);
|
||||
@ -8220,8 +8227,11 @@ gf_cli_status_cbk(struct rpc_req *req, struct iovec *iov, int count,
|
||||
}
|
||||
|
||||
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_unserialize(rsp.dict.dict_val, rsp.dict.dict_len, &dict);
|
||||
if (ret)
|
||||
@ -9089,6 +9099,7 @@ gf_cli_heal_volume_cbk(struct rpc_req *req, struct iovec *iov, int count,
|
||||
|
||||
if (!brick_count) {
|
||||
cli_err("All bricks of volume %s are down.", volname);
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
|
||||
@ -10518,11 +10529,13 @@ gf_cli_generate_snapshot_event(gf_cli_rsp *rsp, dict_t *dict, int32_t type,
|
||||
}
|
||||
|
||||
if (!snap_uuid) {
|
||||
ret = -1;
|
||||
gf_log("cli", GF_LOG_ERROR, "Failed to get snap uuid");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!volname) {
|
||||
ret = -1;
|
||||
gf_log("cli", GF_LOG_ERROR, "Failed to get volname");
|
||||
goto out;
|
||||
}
|
||||
@ -10566,6 +10579,7 @@ gf_cli_generate_snapshot_event(gf_cli_rsp *rsp, dict_t *dict, int32_t type,
|
||||
}
|
||||
|
||||
if (!snap_uuid) {
|
||||
ret = -1;
|
||||
gf_log("cli", GF_LOG_ERROR, "Failed to get snap uuid");
|
||||
goto out;
|
||||
}
|
||||
@ -10601,6 +10615,7 @@ gf_cli_generate_snapshot_event(gf_cli_rsp *rsp, dict_t *dict, int32_t type,
|
||||
}
|
||||
|
||||
if (!snap_uuid) {
|
||||
ret = -1;
|
||||
gf_log("cli", GF_LOG_ERROR, "Failed to get snap uuid");
|
||||
goto out;
|
||||
}
|
||||
@ -10826,11 +10841,13 @@ gf_cli_snapshot_cbk(struct rpc_req *req, struct iovec *iov, int count,
|
||||
}
|
||||
|
||||
if (!snap_name) {
|
||||
ret = -1;
|
||||
gf_log("cli", GF_LOG_ERROR, "Failed to get snap name");
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!volname) {
|
||||
ret = -1;
|
||||
gf_log("cli", GF_LOG_ERROR, "Failed to get volume name");
|
||||
goto out;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user