transport: fix leak with transport helper URLs
PATCH 1/1 transport: fix leak with transport helper URLs
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.
---
* 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(-)
transport.c +3 -1
@@ -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 )) {
Signature · 1 line
2.46.0-313-g2d45963c97
Quoted 10 lines · Junio C Hamano
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 <[email protected]>Signed-off-by Junio C Hamano <[email protected]>
I saw that you've merged this to next already, but: this looks good to me, thanks!
Patrick
Quoted 9 lines · Patrick Steinhardt
Quoted 8 lines · Junio C Hamano
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.
Quoted 7 lines
Quoted 2 lines
Helped-by Patrick Steinhardt <[email protected]>Signed-off-by Junio C Hamano <[email protected]>I saw that you've merged this to
nextalready, but: this looks good to me, thanks!Patrick
I just noticed that this also makes a couple of test suites pass with leak checking enabled. So below diff should likely be applied on top.
Patrick
t/t5509-fetch-push-namespaces.sh +1 -0
@@ -4,6 +4,7 @@ test_description='fetch/push involving ref namespaces' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup '
t/t5802-connect-helper.sh +2 -0
@@ -1,6 +1,8 @@ #!/bin/sh test_description='ext::cmd remote "connect" helper' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup '
t/t5814-proto-disable-ext.sh +2 -0
@@ -1,6 +1,8 @@ #!/bin/sh test_description='test disabling of remote-helper paths in clone/fetch' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY/lib-proto-disable.sh"
t/t5815-submodule-protos.sh +2 -0
@@ -1,6 +1,8 @@ #!/bin/sh test_description='test protocol filtering with submodules' + +TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh . "$TEST_DIRECTORY"/lib-proto-disable.sh
Quoted 7 lines · Patrick Steinhardt
Quoted 4 lines
I saw that you've merged this to
nextalready, but: this looks good to me, thanks!Patrick
I just noticed that this also makes a couple of test suites pass with leak checking enabled. So below diff should likely be applied on top.
I'll think about it. I do not want to see too many "ok, we have now marked this as leak-free" plus "ouch, we have unrelated fix and its test now triggers leaks from another subsystem we happen to use", especially when our primary business is not leak-plugging (e.g., the "ls-remote outside a repo" use case was a real regression fix even though it sort of falls into "if it hurts, don't do it" category).
Thanks.