tc_util: detect overflow in get_size

This detects overflow during parsing of value using get_size:

eg. running:

$ tc qdisc add dev lo root cake memlimit 11gb

currently gives a memlimit of "3072Mb", while with this patch it errors
with 'illegal value for "memlimit": "11gb"', since memlinit is an
unsigned integer.

Signed-off-by: Odin Ugedal <odin@ugedal.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
This commit is contained in:
Odin Ugedal 2020-04-16 16:08:14 +02:00 committed by Stephen Hemminger
parent fe821d64e6
commit e07c57e94e

View File

@ -385,6 +385,11 @@ int get_size(unsigned int *size, const char *str)
} }
*size = sz; *size = sz;
/* detect if an overflow happened */
if (*size != floor(sz))
return -1;
return 0; return 0;
} }