1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-06-03 01:46:11 +02:00

stat_opt: check extra strlen call

As in earlier commits, the diff option parser uses
starts_with to find that an argument starts with "--stat-",
and then adds strlen("stat-") to find the rest of the
option.

However, in this case the starts_with and the strlen are
separated across functions, making it easy to call the
latter without the former. Let's use skip_prefix instead of
raw pointer arithmetic to catch such a case.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King 2014-06-18 15:51:17 -04:00 committed by Junio C Hamano
parent d12c24d2a9
commit 0539cc0038

3
diff.c
View File

@ -3422,7 +3422,8 @@ static int stat_opt(struct diff_options *options, const char **av)
int count = options->stat_count;
int argcount = 1;
arg += strlen("--stat");
if (!skip_prefix(arg, "--stat", &arg))
die("BUG: stat option does not begin with --stat: %s", arg);
end = (char *)arg;
switch (*arg) {