From: Junio C Hamano <gitster@pobox.com>
To: git@vger.kernel.org
Subject: [PATCH] transport: fix leak with transport helper URLs
Date: Wed, 07 Aug 2024 18:11:10 -0700 [thread overview]
Message-ID: <xmqq34nfn7ip.fsf@gitster.g> (raw)
Transport URLs can be prefixed with "foo::", which would tell us that
the transport uses a remote helper called "foo". We extract the helper
name by `xstrndup()`ing the prefix before the double-colons, but never
free that string.
Fix this leak by assigning the result to a separate local variable that
we can then free upon returning.
Helped-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
* It turns out that Patrick planned to have an almost identical
patch, I am queuing this "independently invented" one now,
because a recent update to ls-remote and its tests started
breaking the CI.
transport.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/transport.c b/transport.c
index 12cc5b4d96..7c4af9f56f 100644
--- a/transport.c
+++ b/transport.c
@@ -1115,6 +1115,7 @@ static struct transport_vtable builtin_smart_vtable = {
struct transport *transport_get(struct remote *remote, const char *url)
{
const char *helper;
+ char *helper_to_free = NULL;
const char *p;
struct transport *ret = xcalloc(1, sizeof(*ret));
@@ -1139,10 +1140,11 @@ struct transport *transport_get(struct remote *remote, const char *url)
while (is_urlschemechar(p == url, *p))
p++;
if (starts_with(p, "::"))
- helper = xstrndup(url, p - url);
+ helper = helper_to_free = xstrndup(url, p - url);
if (helper) {
transport_helper_init(ret, helper);
+ free(helper_to_free);
} else if (starts_with(url, "rsync:")) {
die(_("git-over-rsync is no longer supported"));
} else if (url_is_local_not_ssh(url) && is_file(url) && is_bundle(url, 1)) {
--
2.46.0-313-g2d45963c97
next reply other threads:[~2024-08-08 1:11 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-08 1:11 Junio C Hamano [this message]
2024-08-08 4:52 ` [PATCH] transport: fix leak with transport helper URLs Patrick Steinhardt
2024-08-08 5:22 ` Patrick Steinhardt
2024-08-08 16:14 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq34nfn7ip.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).