Skip to content

Commit e3fa568

Browse files
committed
revision: parse "git log -<count>" more carefully
This mistyped command line simply ignores "master" and ends up showing two commits from the current HEAD: $ git log -2master because we feed "2master" to atoi() without making sure that the whole string is parsed as an integer. Use the strtol_i() helper function instead. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7bbc4e8 commit e3fa568

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

revision.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,8 +1612,10 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
16121612
revs->skip_count = atoi(optarg);
16131613
return argcount;
16141614
} else if ((*arg == '-') && isdigit(arg[1])) {
1615-
/* accept -<digit>, like traditional "head" */
1616-
revs->max_count = atoi(arg + 1);
1615+
/* accept -<digit>, like traditional "head" */
1616+
if (strtol_i(arg + 1, 10, &revs->max_count) < 0 ||
1617+
revs->max_count < 0)
1618+
die("'%s': not a non-negative integer", arg + 1);
16171619
revs->no_walk = 0;
16181620
} else if (!strcmp(arg, "-n")) {
16191621
if (argc <= 1)

0 commit comments

Comments
 (0)