Skip to content

Commit

Permalink
config: copy the return value of prefix_filename
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Feb 17, 2012
1 parent 27370b1 commit 839de25
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions builtin/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,10 @@ int cmd_config(int argc, const char **argv, const char *prefix)
config_exclusive_filename = git_pathdup("config");
else if (given_config_file) {
if (!is_absolute_path(given_config_file) && prefix)
config_exclusive_filename = prefix_filename(prefix,
strlen(prefix),
given_config_file);
config_exclusive_filename =
xstrdup(prefix_filename(prefix,
strlen(prefix),
given_config_file));
else
config_exclusive_filename = given_config_file;
}
Expand Down

0 comments on commit 839de25

Please sign in to comment.