summaryrefslogtreecommitdiff
path: root/builtin/rev-parse.c
diff options
context:
space:
mode:
authorDavid Sharp <dhsharp@google.com>2014-01-28 21:21:00 (GMT)
committerJunio C Hamano <gitster@pobox.com>2014-01-28 22:10:06 (GMT)
commita43219f2aaa39fbc53ba0aee2481e1cca3c0e649 (patch)
tree4f8d96983cf247a21d48df911ccb1a71a750074f /builtin/rev-parse.c
parentd2446dfd7f3b3f8948142cfb07a0270e2497d93f (diff)
downloadgit-a43219f2aaa39fbc53ba0aee2481e1cca3c0e649.zip
git-a43219f2aaa39fbc53ba0aee2481e1cca3c0e649.tar.gz
git-a43219f2aaa39fbc53ba0aee2481e1cca3c0e649.tar.bz2
rev-parse: check i before using argv[i] against argc
The --prefix, --default, and --resolve-git-dir options to git-rev-parse require an argument, but when given no argument, the code uses the NULL read from argv[argc] without checking, leading to a segfault. Instead, check first and die() with an error message. Signed-off-by: David Sharp <dhsharp@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/rev-parse.c')
-rw-r--r--builtin/rev-parse.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index c76b89d..068fd17 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -523,15 +523,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")) {
@@ -703,9 +705,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;
}