diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2023-12-09 17:02:57 -0500 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2023-12-09 17:02:57 -0500 |
commit | e0d7dc5dfd7bdaa62b6bc18e9c1cce00bbe08577 (patch) | |
tree | 24b2cddb84bc800f946cb1a5b1f4e53a7668504b /src/parse.c | |
parent | deb293c7fb3ac0787ba9de8d4423b0037998fc13 (diff) | |
download | bfs-e0d7dc5dfd7bdaa62b6bc18e9c1cce00bbe08577.tar.xz |
parse: Reject integers that start with whitespace
Diffstat (limited to 'src/parse.c')
-rw-r--r-- | src/parse.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/parse.c b/src/parse.c index 13e65bc..778fc68 100644 --- a/src/parse.c +++ b/src/parse.c @@ -565,13 +565,17 @@ enum int_flags { * Parse an integer. */ static const char *parse_int(const struct parser_state *state, char **arg, const char *str, void *result, enum int_flags flags) { - char *endptr; + // strtoll() skips leading spaces, but we want to reject them + if (xisspace(str[0])) { + goto bad; + } int base = flags & IF_BASE_MASK; if (base == 0) { base = 10; } + char *endptr; errno = 0; long long value = strtoll(str, &endptr, base); if (errno != 0) { |