config: make a copy of $GIT_CONFIG string
authorJeff King <peff@peff.net>
Fri, 11 Jan 2019 22:15:54 +0000 (17:15 -0500)
committerJunio C Hamano <gitster@pobox.com>
Sat, 12 Jan 2019 02:48:58 +0000 (18:48 -0800)
cmd_config() points our source filename pointer at the return value of
getenv(), but that value may be invalidated by further calls to
environment functions. Let's copy it to make sure it remains valid.

We don't need to bother freeing it, as it remains part of the
whole-process global state until we exit.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/config.c
index 97b58c4aeac4a390148192578d92191407ec7e13..752d0c65d76ca94498ce413f79efde208399b3e5 100644 (file)
@@ -595,7 +595,7 @@ int cmd_config(int argc, const char **argv, const char *prefix)
        int nongit = !startup_info->have_repository;
        char *value;
 
-       given_config_source.file = getenv(CONFIG_ENVIRONMENT);
+       given_config_source.file = xstrdup_or_null(getenv(CONFIG_ENVIRONMENT));
 
        argc = parse_options(argc, argv, prefix, builtin_config_options,
                             builtin_config_usage,