Skip to content

Commit 06f3549

Browse files
jrngitster
authored andcommitted
setup: make sure git dir path is in a permanent buffer
If setup_git_env() is run before the usual repository discovery sequence and .git is a file with the text gitdir: <path> (with <path> any string) then the in-core git_dir variable is set to the result of converting <path> to an absolute path using make_absolute_path(). Unfortunately make_absolute_path() returns its result in a static buffer that is overwritten by later calls. Such a call could cause later accesses to git_dir (from git_pathdup(), for example) to read the wrong path, leaving git very confused. It is not obvious whether any existing code in git will trigger the problem, but in any case, it is worth a few dozen bytes to copy the return value from make_absolute_path() for some added peace of mind. Signed-off-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7f7868e commit 06f3549

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

environment.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,10 @@ const char * const local_repo_env[LOCAL_REPO_ENV_SIZE + 1] = {
8787
static void setup_git_env(void)
8888
{
8989
git_dir = getenv(GIT_DIR_ENVIRONMENT);
90-
if (!git_dir)
90+
if (!git_dir) {
9191
git_dir = read_gitfile_gently(DEFAULT_GIT_DIR_ENVIRONMENT);
92+
git_dir = git_dir ? xstrdup(git_dir) : NULL;
93+
}
9294
if (!git_dir)
9395
git_dir = DEFAULT_GIT_DIR_ENVIRONMENT;
9496
git_object_dir = getenv(DB_ENVIRONMENT);

0 commit comments

Comments
 (0)