From: Jeff King Date: Fri, 11 Jan 2019 22:15:00 +0000 (-0500) Subject: get_super_prefix(): copy getenv() result X-Git-Tag: v2.21.0-rc0~69^2~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8aac69038fa6c5f957559ca7e08a5e2e8f74d0fa;p=git 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 Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- diff --git a/environment.c b/environment.c index 3f3c8746c2..8fa10cc431 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;