From e0d7dc5dfd7bdaa62b6bc18e9c1cce00bbe08577 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Sat, 9 Dec 2023 17:02:57 -0500 Subject: parse: Reject integers that start with whitespace --- src/parse.c | 6 +++++- tests/bfs/links_leading_space.sh | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 tests/bfs/links_leading_space.sh 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' -- cgit v1.2.3