From: Jens Axboe Date: Mon, 14 Oct 2019 14:03:53 +0000 (-0600) Subject: parse: improve detection of bad input string X-Git-Tag: fio-3.17~34 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=5cd4efe903798f2185a347911a9440324558c89f parse: improve detection of bad input string If we attempt to do number conversion, and strtoll() returns 0 AND the end pointer is the same as the starting string, then fail the conversion. Fixes: https://github.com/axboe/fio/issues/841 Signed-off-by: Jens Axboe --- diff --git a/parse.c b/parse.c index c4fd4626..483a62f6 100644 --- a/parse.c +++ b/parse.c @@ -373,12 +373,16 @@ int str_to_decimal(const char *str, long long *val, int kilo, void *data, #endif if (rc == 1) { + char *endptr; + if (strstr(str, "0x") || strstr(str, "0X")) base = 16; else base = 10; - *val = strtoll(str, NULL, base); + *val = strtoll(str, &endptr, base); + if (*val == 0 && endptr == str) + return 1; if (*val == LONG_MAX && errno == ERANGE) return 1; }