Skip to content

Commit 0bf3c96

Browse files
peffdscho
authored andcommitted
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 <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ce83ddc commit 0bf3c96

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

environment.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ char *git_work_tree_cfg;
107107

108108
static char *git_namespace;
109109

110-
static const char *super_prefix;
110+
static char *super_prefix;
111111

112112
/*
113113
* Repository-local GIT_* environment variables; see cache.h for details.
@@ -240,7 +240,7 @@ const char *get_super_prefix(void)
240240
{
241241
static int initialized;
242242
if (!initialized) {
243-
super_prefix = getenv(GIT_SUPER_PREFIX_ENVIRONMENT);
243+
super_prefix = xstrdup_or_null(getenv(GIT_SUPER_PREFIX_ENVIRONMENT));
244244
initialized = 1;
245245
}
246246
return super_prefix;

0 commit comments

Comments
 (0)