summaryrefslogtreecommitdiff
path: root/environment.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2019-01-11 22:15:00 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-01-12 02:48:58 (GMT)
commit8aac69038fa6c5f957559ca7e08a5e2e8f74d0fa (patch)
tree0e6939eaca33b1f4075107f4374e082a1e69d657 /environment.c
parent98cdfbb84ad2ed6a2eb43dafa357a70a4b0a0fad (diff)
downloadgit-8aac69038fa6c5f957559ca7e08a5e2e8f74d0fa.zip
git-8aac69038fa6c5f957559ca7e08a5e2e8f74d0fa.tar.gz
git-8aac69038fa6c5f957559ca7e08a5e2e8f74d0fa.tar.bz2
get_super_prefix(): copy getenv() result
The return value of getenv() is not guaranteed to remain valid across multiple calls (nor across calls to setenv()). Since this function caches the result for the length of the program, we must make a copy to ensure that it is still valid when we need it. Reported-by: Yngve N. Pettersen <yngve@vivaldi.com> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'environment.c')
-rw-r--r--environment.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/environment.c b/environment.c
index 3f3c8746..8fa10cc 100644
--- a/environment.c
+++ b/environment.c
@@ -107,7 +107,7 @@ char *git_work_tree_cfg;
static char *git_namespace;
-static const char *super_prefix;
+static char *super_prefix;
/*
* Repository-local GIT_* environment variables; see cache.h for details.
@@ -240,7 +240,7 @@ const char *get_super_prefix(void)
{
static int initialized;
if (!initialized) {
- super_prefix = getenv(GIT_SUPER_PREFIX_ENVIRONMENT);
+ super_prefix = xstrdup_or_null(getenv(GIT_SUPER_PREFIX_ENVIRONMENT));
initialized = 1;
}
return super_prefix;