summaryrefslogtreecommitdiffstats
path: root/cli
diff options
context:
space:
mode:
authorAtin Mukherjee <amukherj@redhat.com>2017-02-09 16:09:08 +0530
committerShyamsundar Ranganathan <srangana@redhat.com>2017-02-10 06:40:28 -0500
commit2a596acfd054afda5234083b675d5fd4bc171a21 (patch)
tree514e5feee18a2ed196827e86703deef738e9d036 /cli
parent226d7c442509172b2209515841ef499ec12fc9f2 (diff)
cli: add integer check for timeout option
>Reviewed-on: https://review.gluster.org/16578 >NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> >CentOS-regression: Gluster Build System <jenkins@build.gluster.org> >Smoke: Gluster Build System <jenkins@build.gluster.org> >Reviewed-by: Prashanth Pai <ppai@redhat.com> >Reviewed-by: Samikshan Bairagya <samikshan@gmail.com> >(cherry picked from commit 421a098d2acfd4b837d4c03ea6f69987c670d3f7) Change-Id: Ia9f2d343e0a9ad13af1a62abe8946d646d36b3bb BUG: 1421017 Signed-off-by: Atin Mukherjee <amukherj@redhat.com> Reviewed-on: https://review.gluster.org/16595 Smoke: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Prashanth Pai <ppai@redhat.com> NetBSD-regression: NetBSD Build System <jenkins@build.gluster.org> CentOS-regression: Gluster Build System <jenkins@build.gluster.org> Reviewed-by: Shyamsundar Ranganathan <srangana@redhat.com>
Diffstat (limited to 'cli')
-rw-r--r--cli/src/cli.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/cli/src/cli.c b/cli/src/cli.c
index 422dad2a694..1710724abd6 100644
--- a/cli/src/cli.c
+++ b/cli/src/cli.c
@@ -289,11 +289,31 @@ cli_rpc_notify (struct rpc_clnt *rpc, void *mydata, rpc_clnt_event_t event,
return ret;
}
+static gf_boolean_t
+is_valid_int (char *str)
+{
+ if (*str == '-')
+ ++str;
+
+ /* Handle empty string or just "-".*/
+ if (!*str)
+ return _gf_false;
+
+ /* Check for non-digit chars in the rest of the string */
+ while (*str) {
+ if (!isdigit(*str))
+ return _gf_false;
+ else
+ ++str;
+ }
+ return _gf_true;
+}
/*
* ret: 0: option successfully processed
* 1: signalling end of option list
- * -1: unknown option or other issue
+ * -1: unknown option
+ * -2: parsing issue (avoid unknown option error)
*/
int
cli_opt_parse (char *opt, struct cli_state *state)
@@ -359,6 +379,11 @@ cli_opt_parse (char *opt, struct cli_state *state)
}
oarg = strtail (opt, "timeout=");
if (oarg) {
+ if (!is_valid_int (oarg) || atoi(oarg) <= 0) {
+ cli_err ("timeout value should be a postive integer");
+ return -2; /* -2 instead of -1 to avoid unknown option
+ error */
+ }
cli_default_conn_timeout = atoi(oarg);
return 0;
}
@@ -424,6 +449,8 @@ parse_cmdline (int argc, char *argv[], struct cli_state *state)
if (ret == -1) {
cli_out ("unrecognized option --%s", opt);
return ret;
+ } else if (ret == -2) {
+ return ret;
}
for (j = i; j < state->argc - 1; j++)
state->argv[j] = state->argv[j + 1];