summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2014-06-06 15:33:25 -0700
committerJunio C Hamano <gitster@pobox.com>2014-06-09 14:53:49 -0700
commite3fa568cb397a78a56716137c826f21f5e0b0a77 (patch)
tree24f341eb3297d88a6cd3e21bbfe3110e2237d046
parent7bbc4e8fdb33e0a8e42e77cc05460d4c4f615f4d (diff)
downloadgit-e3fa568cb397a78a56716137c826f21f5e0b0a77.tar.gz
revision: parse "git log -<count>" more carefullyjc/revision-dash-count-parsing
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>
-rw-r--r--revision.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/revision.c b/revision.c
index 7afedc50fc..d5e2f1a257 100644
--- a/revision.c
+++ b/revision.c
@@ -1612,8 +1612,10 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
revs->skip_count = atoi(optarg);
return argcount;
} else if ((*arg == '-') && isdigit(arg[1])) {
- /* accept -<digit>, like traditional "head" */
- revs->max_count = atoi(arg + 1);
+ /* accept -<digit>, like traditional "head" */
+ if (strtol_i(arg + 1, 10, &revs->max_count) < 0 ||
+ revs->max_count < 0)
+ die("'%s': not a non-negative integer", arg + 1);
revs->no_walk = 0;
} else if (!strcmp(arg, "-n")) {
if (argc <= 1)