]> git.ipfire.org Git - thirdparty/git.git/commitdiff
transport: fix leak with transport helper URLs
authorJunio C Hamano <gitster@pobox.com>
Thu, 8 Aug 2024 00:32:56 +0000 (17:32 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 8 Aug 2024 00:38:31 +0000 (17:38 -0700)
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>
transport.c

index 12cc5b4d9676a5b3be166f1d33e5b6616073da93..7c4af9f56f2c10366acd398ed81df7090d35266f 100644 (file)
@@ -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)) {