Skip to content

Commit 839de25

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 27370b1 commit 839de25

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

builtin/config.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,10 @@ int cmd_config(int argc, const char **argv, const char *prefix)
377377
config_exclusive_filename = git_pathdup("config");
378378
else if (given_config_file) {
379379
if (!is_absolute_path(given_config_file) && prefix)
380-
config_exclusive_filename = prefix_filename(prefix,
381-
strlen(prefix),
382-
given_config_file);
380+
config_exclusive_filename =
381+
xstrdup(prefix_filename(prefix,
382+
strlen(prefix),
383+
given_config_file));
383384
else
384385
config_exclusive_filename = given_config_file;
385386
}

0 commit comments

Comments
 (0)