From 39bfcc7f27b5c5173455140abf902b38c21f0acb Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Sun, 1 Mar 2020 21:54:08 +0100 Subject: Fix: Replace bit shifts in parse_size with SZ_MUL_OV On 32 bit systems, size_t is a 32 bit integer and doing 64 bit shifts won't do us any good. So instead, use the existing size_t multiply and catch overflow macros. Signed-off-by: David Oberhollenzer --- lib/common/parse_size.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/common/parse_size.c b/lib/common/parse_size.c index 1285d3b..3e79a19 100644 --- a/lib/common/parse_size.c +++ b/lib/common/parse_size.c @@ -31,23 +31,20 @@ int parse_size(const char *what, size_t *out, const char *str, switch (*in) { case 'k': case 'K': - if (acc > ((1UL << (SIZEOF_SIZE_T * CHAR_BIT - 10)) - 1UL)) + if (SZ_MUL_OV(acc, 1024, &acc)) goto fail_ov; - acc <<= 10; ++in; break; case 'm': case 'M': - if (acc > ((1UL << (SIZEOF_SIZE_T * CHAR_BIT - 20)) - 1UL)) + if (SZ_MUL_OV(acc, 1048576, &acc)) goto fail_ov; - acc <<= 20; ++in; break; case 'g': case 'G': - if (acc > ((1UL << (SIZEOF_SIZE_T * CHAR_BIT - 30)) - 1UL)) + if (SZ_MUL_OV(acc, 1073741824, &acc)) goto fail_ov; - acc <<= 30; ++in; break; case '%': -- cgit v1.2.3