From 566627a3d3c91b3359f1da5fda00d528e18aae37 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 12 Dec 2017 12:29:07 +0100 Subject: cli: Be more strict about what size units we expect. Only accept b,B,k(iB),K(iB),M(iB),G(iB),T(iB),... Fail on all other with an improved error message. Resolves: https://github.com/gluster/gluster-block/issues/44 Change-Id: I6ac7e9359f3b8d8afaad254ea12c30131ed676d8 Signed-off-by: Michael Adam --- utils/common.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/utils/common.c b/utils/common.c index 8a8f303..4b9237f 100644 --- a/utils/common.c +++ b/utils/common.c @@ -88,14 +88,27 @@ glusterBlockParseSize(const char *dom, char *value) case 'B': case 'b': case '\0': - return sizef; break; default: - LOG(dom, GB_LOG_ERROR, "%s", - "You may use k/K, M, G or T suffixes for kilobytes, " - "megabytes, gigabytes and terabytes."); - return -1; + goto fail; + } + + if ((strlen(tmp) > 1) && + ((tmp[0] == 'b') || (tmp[0] == 'B') || + (strncasecmp(tmp+1, "ib", strlen(tmp+1)) != 0))) + { + goto fail; } + + /* success */ + return sizef; + +fail: + LOG(dom, GB_LOG_ERROR, "%s", + "Unknown size unit. " + "You may use b/B, k/K(iB), M(iB), G(iB), and T(iB) suffixes for " + "bytes, kibibytes, mebibytes, gibibytes, and tebibytes."); + return -1; } -- cgit