summaryrefslogtreecommitdiff
path: root/builtin/checkout.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2017-03-28 19:46:30 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-03-30 21:59:50 (GMT)
commit7f897b6f176319ec0f490d286c3fee11187d7095 (patch)
tree94b0539edf7f759fefd19856f588882d0135c1df /builtin/checkout.c
parent1412f762e0363c126ea011682b61a8c9d7d7456f (diff)
downloadgit-7f897b6f176319ec0f490d286c3fee11187d7095.zip
git-7f897b6f176319ec0f490d286c3fee11187d7095.tar.gz
git-7f897b6f176319ec0f490d286c3fee11187d7095.tar.bz2
avoid using fixed PATH_MAX buffers for refs
Many functions which handle refs use a PATH_MAX-sized buffer to do so. This is mostly reasonable as we have to write loose refs into the filesystem, and at least on Linux the 4K PATH_MAX is big enough that nobody would care. But: 1. The static PATH_MAX is not always the filesystem limit. 2. On other platforms, PATH_MAX may be much smaller. 3. As we move to alternate ref storage, we won't be bound by filesystem limits. Let's convert these to heap buffers so we don't have to worry about truncation or size limits. We may want to eventually constrain ref lengths for sanity and to prevent malicious names, but we should do so consistently across all platforms, and in a central place (like the ref code). Signed-off-by: Jeff King <peff@peff.net>
Diffstat (limited to 'builtin/checkout.c')
-rw-r--r--builtin/checkout.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 3ecc47b..bfa5419 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -908,11 +908,10 @@ static int check_tracking_name(struct remote *remote, void *cb_data)
static const char *unique_tracking_name(const char *name, struct object_id *oid)
{
struct tracking_name_data cb_data = { NULL, NULL, NULL, 1 };
- char src_ref[PATH_MAX];
- snprintf(src_ref, PATH_MAX, "refs/heads/%s", name);
- cb_data.src_ref = src_ref;
+ cb_data.src_ref = xstrfmt("refs/heads/%s", name);
cb_data.dst_oid = oid;
for_each_remote(check_tracking_name, &cb_data);
+ free(cb_data.src_ref);
if (cb_data.unique)
return cb_data.dst_ref;
free(cb_data.dst_ref);