Keep "git --git-dir" from causing a bus error.
The option checking code for --git-dir had an off by 1 error that would cause it to access uninitialized memory if it was the last argument. This causes it to display an error and display the usage string instead. Signed-off-by: Brian Gernhardt <benji@silverinsanity.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Brian Gernhardt committed
Dec 22, 2006 at 08:56 UTC
c321f00d09f56dcf2f149757a2a337f3732f3097
1 file changed
+4
-2
git.c
+4
-2
@@ -59,8 +59,10 @@ static int handle_options(const char*** argv, int* argc)
59
} else if (!strcmp(cmd, "-p") || !strcmp(cmd, "--paginate")) {
60
setup_pager();
61
} else if (!strcmp(cmd, "--git-dir")) {
62
- if (*argc < 1)
63
- return -1;
62
+ if (*argc < 2) {
63
+ fprintf(stderr, "No directory given for --git-dir.\n" );
64
+ usage(git_usage_string);
65
+ }
66
setenv("GIT_DIR", (*argv)[1], 1);
67
(*argv)++;
68
(*argc)--;