diff options
author | Jens Axboe <axboe@kernel.dk> | 2019-10-14 08:03:53 -0600 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2019-10-14 08:03:53 -0600 |
commit | 5cd4efe903798f2185a347911a9440324558c89f (patch) | |
tree | d3039ba213b01fe3c9347c2d202db751c5c8061e | |
parent | 9663e751c25d3bf52e959d8c9025460d2f645b1e (diff) | |
download | fio-5cd4efe903798f2185a347911a9440324558c89f.tar.gz fio-5cd4efe903798f2185a347911a9440324558c89f.tar.bz2 |
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 <axboe@kernel.dk>
-rw-r--r-- | parse.c | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -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; } |