config: copy the return value of prefix_filename

The prefix_filename function returns a pointer to a static
buffer which may be overwritten by subsequent calls. Since
we are going to keep the result around for a while, let's be
sure to duplicate it for safety.

I don't think this can be triggered as a bug in the current
code, but it's a good idea to be defensive, as any resulting
bug would be quite subtle.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King 2012-02-16 03:03:52 -05:00 committed by Junio C Hamano
parent 27370b1170
commit 839de25272

View File

@ -377,9 +377,10 @@ int cmd_config(int argc, const char **argv, const char *prefix)
config_exclusive_filename = git_pathdup("config"); config_exclusive_filename = git_pathdup("config");
else if (given_config_file) { else if (given_config_file) {
if (!is_absolute_path(given_config_file) && prefix) if (!is_absolute_path(given_config_file) && prefix)
config_exclusive_filename = prefix_filename(prefix, config_exclusive_filename =
strlen(prefix), xstrdup(prefix_filename(prefix,
given_config_file); strlen(prefix),
given_config_file));
else else
config_exclusive_filename = given_config_file; config_exclusive_filename = given_config_file;
} }