Browse Source

setup_git_directory: fix segfault if repository is found in cwd

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>
maint
Matthias Lederhofer 18 years ago committed by Junio C Hamano
parent
commit
f4f51add27
  1. 5
      setup.c

5
setup.c

@ -251,6 +251,9 @@ const char *setup_git_directory_gently(int *nongit_ok)
die("Not a git repository"); die("Not a git repository");
} }
setenv(GIT_DIR_ENVIRONMENT, cwd, 1); setenv(GIT_DIR_ENVIRONMENT, cwd, 1);
gitdirenv = getenv(GIT_DIR_ENVIRONMENT);
if (!gitdirenv)
die("getenv after setenv failed");
} }


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

Loading…
Cancel
Save