summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorMichael Adam <obnox@redhat.com>2017-12-12 12:29:07 +0100
committerMichael Adam <obnox@redhat.com>2017-12-12 19:03:51 +0100
commit566627a3d3c91b3359f1da5fda00d528e18aae37 (patch)
treed34f0bf2b3436d1debf616c2acef735feaa45220 /utils
parent019db978d82d850925abaf2651b4ef549ec0f987 (diff)
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 <obnox@redhat.com>
Diffstat (limited to 'utils')
-rw-r--r--utils/common.c23
1 files 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;
}