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 | |
parent | deb293c7fb3ac0787ba9de8d4423b0037998fc13 (diff) | |
download | bfs-e0d7dc5dfd7bdaa62b6bc18e9c1cce00bbe08577.tar.xz |
parse: Reject integers that start with whitespace
-rw-r--r-- | src/parse.c | 6 | ||||
-rw-r--r-- | tests/bfs/links_leading_space.sh | 1 |
2 files changed, 6 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) { diff --git a/tests/bfs/links_leading_space.sh b/tests/bfs/links_leading_space.sh new file mode 100644 index 0000000..15957af --- /dev/null +++ b/tests/bfs/links_leading_space.sh @@ -0,0 +1 @@ +! invoke_bfs links -links ' 1' |