Skip to content

Commit

Permalink
setup_git_directory: fix segfault if repository is found in cwd
Browse files Browse the repository at this point in the history
Additionally there was a similar part calling setenv and getenv
in the same way which missed a check if getenv succeeded.

Signed-off-by: Matthias Lederhofer <matled@gmx.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
matled authored and gitster committed Jun 6, 2007
1 parent 3ae4a86 commit f4f51ad
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ const char *setup_git_directory_gently(int *nongit_ok)
die("Not a git repository");
}
setenv(GIT_DIR_ENVIRONMENT, cwd, 1);
gitdirenv = getenv(GIT_DIR_ENVIRONMENT);
if (!gitdirenv)
die("getenv after setenv failed");
}

if (PATH_MAX - 40 < strlen(gitdirenv)) {
Expand Down Expand Up @@ -290,6 +293,8 @@ const char *setup_git_directory_gently(int *nongit_ok)
if (gitdirenv[0] != '/') {
setenv(GIT_DIR_ENVIRONMENT, gitdir, 1);
gitdirenv = getenv(GIT_DIR_ENVIRONMENT);
if (!gitdirenv)
die("getenv after setenv failed");
if (PATH_MAX - 40 < strlen(gitdirenv)) {
if (nongit_ok) {
*nongit_ok = 1;
Expand Down

0 comments on commit f4f51ad

Please sign in to comment.