Avoid integer overflow in suffix-processing code.

This commit is contained in:
Stephen Heumann 2020-02-06 23:56:57 -06:00
parent a0d9884e7e
commit 2a577970b6
2 changed files with 4 additions and 4 deletions

View File

@ -725,7 +725,7 @@ void generate_uuid(uint8_t *buf) FAST_FUNC;
/* Last element is marked by mult == 0 */
struct suffix_mult {
char suffix[4];
unsigned mult;
unsigned long mult;
};
extern const struct suffix_mult bkm_suffixes[];
#define km_suffixes (bkm_suffixes + 1)

View File

@ -67,7 +67,7 @@ uint16_t FAST_FUNC xatou16(const char *numstr)
const struct suffix_mult bkm_suffixes[] = {
{ "b", 512 },
{ "k", 1024 },
{ "m", 1024*1024 },
{ "m", 1024L*1024 },
{ "", 0 }
};
@ -83,10 +83,10 @@ const struct suffix_mult cwbkMG_suffixes[] = {
{ "K", 1024 }, /* compat with coreutils dd */
{ "MB", 1000000 },
{ "MD", 1000000 },
{ "M", 1024*1024 },
{ "M", 1024L*1024 },
{ "GB", 1000000000 },
{ "GD", 1000000000 },
{ "G", 1024*1024*1024 },
{ "G", 1024L*1024*1024 },
/* "D" suffix for decimal is not in coreutils manpage, looks like it's deprecated */
/* coreutils also understands TPEZY suffixes for tera- and so on, with B suffix for decimal */
{ "", 0 }