diff options
| author | Atin Mukherjee <amukherj@redhat.com> | 2017-02-09 16:09:08 +0530 | 
|---|---|---|
| committer | Atin Mukherjee <amukherj@redhat.com> | 2017-02-10 01:16:30 -0500 | 
| commit | 421a098d2acfd4b837d4c03ea6f69987c670d3f7 (patch) | |
| tree | 2616de18135f5d663f8767475e638c125fdd4bf2 /cli/src | |
| parent | 0e03336a9362e5717e561f76b0c543e5a197b31b (diff) | |
cli: add integer check for timeout option
Change-Id: Ia9f2d343e0a9ad13af1a62abe8946d646d36b3bb
BUG: 1420697
Signed-off-by: Atin Mukherjee <amukherj@redhat.com>
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>
Diffstat (limited to 'cli/src')
| -rw-r--r-- | cli/src/cli.c | 29 | 
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];  | 
