Skip to content

Commit dffc651

Browse files
szedergitster
authored andcommitted
revision.c: stricter parsing of '--early-output'
The parsing of '--early-output' with or without its optional integer argument allowed bogus options like '--early-output-foobarbaz' to slip through and be ignored. Fix it by parsing '--early-output' in the same way as other options with an optional argument are parsed. Furthermore, use strtoul_ui() to parse the optional integer argument and to refuse negative numbers. While at it, use skip_prefix() instead of starts_with() and magic numbers. Signed-off-by: SZEDER Gábor <[email protected]> Reviewed-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9ada7ae commit dffc651

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

revision.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1750,16 +1750,13 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
17501750
} else if (!strcmp(arg, "--author-date-order")) {
17511751
revs->sort_order = REV_SORT_BY_AUTHOR_DATE;
17521752
revs->topo_order = 1;
1753-
} else if (starts_with(arg, "--early-output")) {
1754-
int count = 100;
1755-
switch (arg[14]) {
1756-
case '=':
1757-
count = atoi(arg+15);
1758-
/* Fallthrough */
1759-
case 0:
1760-
revs->topo_order = 1;
1761-
revs->early_output = count;
1762-
}
1753+
} else if (!strcmp(arg, "--early-output")) {
1754+
revs->early_output = 100;
1755+
revs->topo_order = 1;
1756+
} else if (skip_prefix(arg, "--early-output=", &optarg)) {
1757+
if (strtoul_ui(optarg, 10, &revs->early_output) < 0)
1758+
die("'%s': not a non-negative integer", optarg);
1759+
revs->topo_order = 1;
17631760
} else if (!strcmp(arg, "--parents")) {
17641761
revs->rewrite_parents = 1;
17651762
revs->print_parents = 1;

0 commit comments

Comments
 (0)