Skip to content

Commit

Permalink
parse: Reject integers that start with whitespace
Browse files Browse the repository at this point in the history
  • Loading branch information
tavianator committed Dec 9, 2023
1 parent deb293c commit e0d7dc5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions tests/bfs/links_leading_space.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
! invoke_bfs links -links ' 1'

0 comments on commit e0d7dc5

Please sign in to comment.