From c68b1e28ae9b7528aa844764e719c7267976be83 Mon Sep 17 00:00:00 2001 From: shishir gowda Date: Thu, 31 Mar 2011 04:57:05 +0000 Subject: TOP: Validate command options Signed-off-by: shishir gowda Signed-off-by: Vijay Bellur BUG: 2628 () URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2628 --- libglusterfs/src/common-utils.c | 31 +++++++++++++++++++++++++++++++ libglusterfs/src/common-utils.h | 1 + 2 files changed, 32 insertions(+) (limited to 'libglusterfs') diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 21506636cd7..0d850740eee 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 7a18b12cda2..eb3e121779d 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 */ -- cgit