From 793f8491789e58791b090a74472959df117e404b Mon Sep 17 00:00:00 2001 From: Kaushal M Date: Thu, 10 Oct 2013 17:20:57 +0530 Subject: libglusterfs: Account for overflow in gf_string2bytesize gf_string2bytesize will now return an error when a value is greater than UINT64_MAX and set errno to EOVERFLOW. This is needed because casting a double value greater than UINT64_MAX to uint64_t will convert it to 0. BUG: 1017746 Change-Id: I6f96efc1e3a1c236685593a6fb7f806a87e46019 Signed-off-by: Kaushal M Reviewed-on: http://review.gluster.org/6068 Tested-by: Gluster Build System Reviewed-by: Anand Avati --- libglusterfs/src/common-utils.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'libglusterfs') diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index d57cd8a55..c37a876df 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -1500,6 +1500,12 @@ gf_string2percent_or_bytesize (const char *str, return -1; } + /* Error out if we cannot store the value in uint64 */ + if (value > UINT64_MAX) { + errno = EOVERFLOW; + return -1; + } + *n = (uint64_t) value; return 0; -- cgit