summaryrefslogtreecommitdiff
path: root/unpack-trees.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2015-08-10 05:35:31 -0400
committerJunio C Hamano <gitster@pobox.com>2015-08-10 15:37:12 -0700
commitfcd12db6af118b70b5c15cf5fdd6800eeecc370a (patch)
tree8050bcc9515081c8a6a52285297fe23f0bf08916 /unpack-trees.c
parent77b9b1d13ac9e6b78ba676d4edb221b7d2273c62 (diff)
downloadgit-fcd12db6af118b70b5c15cf5fdd6800eeecc370a.tar.gz
prefer git_pathdup to git_path in some possibly-dangerous cases
Because git_path uses a static buffer that is shared with calls to git_path, mkpath, etc, it can be dangerous to assign the result to a variable or pass it to a non-trivial function. The value may change unexpectedly due to other calls. None of the cases changed here has a known bug, but they're worth converting away from git_path because: 1. It's easy to use git_pathdup in these cases. 2. They use constructs (like assignment) that make it hard to tell whether they're safe or not. The extra malloc overhead should be trivial, as an allocation should be an order of magnitude cheaper than a system call (which we are clearly about to make, since we are constructing a filename). The real cost is that we must remember to free the result. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'unpack-trees.c')
-rw-r--r--unpack-trees.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/unpack-trees.c b/unpack-trees.c
index d6cf84904f..7bb446a4af 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -1029,10 +1029,12 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
if (!core_apply_sparse_checkout || !o->update)
o->skip_sparse_checkout = 1;
if (!o->skip_sparse_checkout) {
- if (add_excludes_from_file_to_list(git_path("info/sparse-checkout"), "", 0, &el, 0) < 0)
+ char *sparse = git_pathdup("info/sparse-checkout");
+ if (add_excludes_from_file_to_list(sparse, "", 0, &el, 0) < 0)
o->skip_sparse_checkout = 1;
else
o->el = &el;
+ free(sparse);
}
memset(&o->result, 0, sizeof(o->result));