From: Jeff King Date: Wed, 18 Jun 2014 19:51:17 +0000 (-0400) Subject: stat_opt: check extra strlen call X-Git-Tag: v2.1.0-rc0~64^2~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0539cc0038ff3411da1fea342b7d6615643bff5b;p=thirdparty%2Fgit.git 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 Signed-off-by: Junio C Hamano --- diff --git a/diff.c b/diff.c index 2378ae49c6..06bdfb8ae5 100644 --- a/diff.c +++ b/diff.c @@ -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) {