1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-27 11:06:09 +02:00

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>
This commit is contained in:
Jeff King 2019-01-11 17:15:00 -05:00 committed by Junio C Hamano
parent 98cdfbb84a
commit 8aac69038f

View File

@ -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;