diff options
author | Junio C Hamano <gitster@pobox.com> | 2014-03-18 14:01:05 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-03-18 14:01:05 -0700 |
commit | c7b317320c1301b6bcf4eb4ac824b76114068f11 (patch) | |
tree | e26f8e8a642107b217b0ed39429be9be72eb3ddd | |
parent | 6f0166771aadeb069b8952255414d67b643db1bf (diff) | |
parent | a43219f2aaa39fbc53ba0aee2481e1cca3c0e649 (diff) | |
download | git-c7b317320c1301b6bcf4eb4ac824b76114068f11.tar.gz git-c7b317320c1301b6bcf4eb4ac824b76114068f11.tar.xz |
Merge branch 'ds/rev-parse-required-args' into maint
"git rev-parse" was loose in rejecting command line arguments that
do not make sense, e.g. "--default" without the required value for
that option.
* ds/rev-parse-required-args:
rev-parse: check i before using argv[i] against argc
-rw-r--r-- | builtin/rev-parse.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index aaeb611a9..45901df37 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -547,15 +547,17 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) continue; } if (!strcmp(arg, "--default")) { - def = argv[i+1]; - i++; + def = argv[++i]; + if (!def) + die("--default requires an argument"); continue; } if (!strcmp(arg, "--prefix")) { - prefix = argv[i+1]; + prefix = argv[++i]; + if (!prefix) + die("--prefix requires an argument"); startup_info->prefix = prefix; output_prefix = 1; - i++; continue; } if (!strcmp(arg, "--revs-only")) { @@ -738,9 +740,12 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix) continue; } if (!strcmp(arg, "--resolve-git-dir")) { - const char *gitdir = resolve_gitdir(argv[i+1]); + const char *gitdir = argv[++i]; if (!gitdir) - die("not a gitdir '%s'", argv[i+1]); + die("--resolve-git-dir requires an argument"); + gitdir = resolve_gitdir(gitdir); + if (!gitdir) + die("not a gitdir '%s'", argv[i]); puts(gitdir); continue; } |