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 <gitster@pobox.com>
Junio C Hamano committed
Jun 6, 2014 at 15:33 UTC
e3fa568cb397a78a56716137c826f21f5e0b0a77
1 file changed
+4
-2
revision.c
+4
-2
@@ -1612,8 +1612,10 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1612
revs->skip_count = atoi(optarg);
1613
return argcount;
1614
} 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);
1619
revs->no_walk = 0;
1620
} else if (!strcmp(arg, "-n")) {
1621
if (argc <= 1)