From c7974318f09ed720471a02f3ec72569d4d7bbdfa Mon Sep 17 00:00:00 2001 From: Kaushal M Date: Thu, 14 Jun 2012 11:53:48 +0530 Subject: libglusterfs: Fix sizet validation for cache-size Validation of 'cache-size' option will not fail when given value is greater than max. Values lesser than min will cause validation to fail. Change-Id: I9c744b5ace10604d5a814e6218ca0d83c796db80 BUG: 831568 Signed-off-by: Kaushal M Reviewed-on: http://review.gluster.com/3570 Tested-by: Gluster Build System Reviewed-by: Jeff Darcy Reviewed-by: Anand Avati --- libglusterfs/src/options.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'libglusterfs/src/options.c') diff --git a/libglusterfs/src/options.c b/libglusterfs/src/options.c index e5025e45ef3..76e581fddb7 100644 --- a/libglusterfs/src/options.c +++ b/libglusterfs/src/options.c @@ -120,7 +120,7 @@ xlator_option_validate_sizet (xlator_t *xl, const char *key, const char *value, volume_option_t *opt, char **op_errstr) { uint64_t size = 0; - int ret = -1; + int ret = 0; char errstr[256]; /* Check the range */ @@ -129,6 +129,7 @@ xlator_option_validate_sizet (xlator_t *xl, const char *key, const char *value, "invalid number format \"%s\" in option \"%s\"", value, key); gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); + ret = -1; goto out; } @@ -136,29 +137,26 @@ xlator_option_validate_sizet (xlator_t *xl, const char *key, const char *value, gf_log (xl->name, GF_LOG_TRACE, "no range check required for 'option %s %s'", key, value); - ret = 0; goto out; } if ((size < opt->min) || (size > opt->max)) { - if (strncmp (key, "cache-size", 10) == 0) { + if ((strncmp (key, "cache-size", 10) == 0) && + (size > opt->max)) { snprintf (errstr, 256, "Cache size %"PRId64" is out of " "range [%"PRId64" - %"PRId64"]", size, opt->min, opt->max); gf_log (xl->name, GF_LOG_WARNING, "%s", errstr); - ret = 0; - goto out; } else { snprintf (errstr, 256, "'%"PRId64"' in 'option %s %s' " "is out of range [%"PRId64" - %"PRId64"]", size, key, value, opt->min, opt->max); gf_log (xl->name, GF_LOG_ERROR, "%s", errstr); - goto out; + ret = -1; } } - ret = 0; out: if (ret && op_errstr) *op_errstr = gf_strdup (errstr); -- cgit