summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--cli/src/cli-cmd-parser.c20
-rw-r--r--libglusterfs/src/common-utils.c31
-rw-r--r--libglusterfs/src/common-utils.h1
3 files changed, 45 insertions, 7 deletions
diff --git a/cli/src/cli-cmd-parser.c b/cli/src/cli-cmd-parser.c
index 69f9565..799a64b 100644
--- a/cli/src/cli-cmd-parser.c
+++ b/cli/src/cli-cmd-parser.c
@@ -1331,15 +1331,19 @@ cli_cmd_volume_top_parse (const char **words, int wordcount,
ret = dict_set_str (dict, "brick", value);
} else if (!strcmp (key, "list-cnt")) {
- list_cnt = atoi(value);
- if (list_cnt < 0 || list_cnt > 100) {
+ ret = gf_is_str_int (value);
+ if (!ret)
+ list_cnt = atoi (value);
+ if (ret || (list_cnt < 0) || (list_cnt > 100)) {
cli_out ("list-cnt should be between 0 to 100");
ret = -1;
goto out;
}
- } else if (perf && !strcmp (key, "bs")){
- blk_size = atoi (value);
- if (blk_size < 0){
+ } else if (perf && !strcmp (key, "bs")) {
+ ret = gf_is_str_int (value);
+ if (!ret)
+ blk_size = atoi (value);
+ if (ret || (blk_size < 0)) {
cli_out ("block size should be an integer "
"greater than zero");
ret = -1;
@@ -1347,8 +1351,10 @@ cli_cmd_volume_top_parse (const char **words, int wordcount,
}
ret = dict_set_int32 (dict, "blk-size", blk_size);
} else if (perf && !strcmp (key, "count")) {
- count = atoi(value);
- if (count < 0 ){
+ ret = gf_is_str_int (value);
+ if (!ret)
+ count = atoi(value);
+ if (ret || (count < 0)) {
cli_out ("count should be an integer greater "
"zero");
ret = -1;
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index 2150663..0d85074 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -1773,3 +1773,34 @@ gf_array_insertionsort (void *A, int l, int r, size_t elem_size,
}
}
}
+
+int
+gf_is_str_int (const char *value)
+{
+ int flag = 0;
+ char *str = NULL;
+ char *fptr = NULL;
+
+ GF_VALIDATE_OR_GOTO ("", value, out);
+
+ str = strdup (value);
+ if (!str)
+ goto out;
+
+ fptr = str;
+
+ while (*str) {
+ if (!isdigit(*str)) {
+ flag = 1;
+ goto out;
+ }
+ str++;
+ }
+
+out:
+ if (fptr)
+ GF_FREE (fptr);
+
+ return flag;
+}
+
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h
index 7a18b12..eb3e121 100644
--- a/libglusterfs/src/common-utils.h
+++ b/libglusterfs/src/common-utils.h
@@ -359,4 +359,5 @@ void _get_md5_str (char *out_str, size_t outlen,
const uint8_t *input, int n);
void gf_array_insertionsort (void *a, int l, int r, size_t elem_size,
gf_cmp cmp);
+int gf_is_str_int (const char *value);
#endif /* _COMMON_UTILS_H */