Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2017-04-04 13:21:19 +0300
committerJunio C Hamano <gitster@pobox.com>2017-04-17 04:24:29 +0300
commita560d87033729d884acb3f198cc52edd6c816416 (patch)
tree8e4fde703c5a5ed231b4540034b2aeec049262d0 /environment.c
parentadac8115a6e7f9841c48e4fe48b74e0ce652ef58 (diff)
environment.c: fix potential segfault by get_git_common_dir()
setup_git_env() must be called before this function to initialize git_common_dir so that it returns a non NULL string. And it must return a non NULL string or segfault can happen because all callers expect so. It does not do so explicitly though and depends on get_git_dir() being called first (which will guarantee setup_git_env()). Avoid this dependency and call setup_git_env() by itself. test-ref-store.c will hit this problem because it's very lightweight, just enough initialization to exercise refs code, and get_git_dir() will never be called until get_worktrees() is, which uses get_git_common_dir and hits a segfault. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'environment.c')
-rw-r--r--environment.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/environment.c b/environment.c
index 42dc3106d2f..2986ee72008 100644
--- a/environment.c
+++ b/environment.c
@@ -214,6 +214,8 @@ const char *get_git_dir(void)
const char *get_git_common_dir(void)
{
+ if (!git_dir)
+ setup_git_env();
return git_common_dir;
}