{"thread":{"id":"56330","subject":"[PATCH] Fix leak in credential_apply_config","startedAt":"2021-08-20T09:15:32Z","lastAt":"2021-08-20T17:57:42Z","messageCount":4,"participants":["Mike Hommey","Derrick Stolee","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"433203","messageId":"20210820084413.1503711-1-mh@glandium.org","threadId":"56330","inReplyTo":null,"subject":"[PATCH] Fix leak in credential_apply_config","fromName":"Mike Hommey","fromEmail":"mh@glandium.org","sentAt":"2021-08-20T08:44:13Z","receivedAt":"2021-08-20T09:15:32Z","isPatch":true,"sender":{"key":"mh@glandium.org","avatar":"https://avatars.githubusercontent.com/u/1038527?v=4"},"body":"Signed-off-by: Mike Hommey <mh@glandium.org>\n---\n credential.c | 1 +\n 1 file changed, 1 insertion(+)\n\ndiff --git a/credential.c b/credential.c\nindex 3c05c7c669..000ac7a8d4 100644\n--- a/credential.c\n+++ b/credential.c\n@@ -128,6 +128,7 @@ static void credential_apply_config(struct credential *c)\n \tnormalized_url = url_normalize(url.buf, &config.url);\n \n \tgit_config(urlmatch_config_entry, &config);\n+\tstring_list_clear(&config.vars, 1);\n \tfree(normalized_url);\n \tstrbuf_release(&url);\n \n-- \n2.33.0\n\n"},{"id":"433224","messageId":"ffa1786e-f69f-3d76-98dc-7fa5cdbd31c0@gmail.com","threadId":"56330","inReplyTo":"20210820084413.1503711-1-mh@glandium.org","subject":"Re: [PATCH] Fix leak in credential_apply_config","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2021-08-20T14:58:56Z","receivedAt":"2021-08-20T14:59:01Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 8/20/2021 4:44 AM, Mike Hommey wrote:\n>  \tnormalized_url = url_normalize(url.buf, &config.url);\n>  \n>  \tgit_config(urlmatch_config_entry, &config);\n> +\tstring_list_clear(&config.vars, 1);\n>  \tfree(normalized_url);\n>  \tstrbuf_release(&url);\n\nA good find! This is obviously correct and a valuable change\nto make. If you are interested in doing a little extra work,\nthen I think there is something more we could do here.\n\nI took a look at the rest of \"struct urlmatch_config\" to see\nif anything else needed to be cleared, and it turns out that\nconfig.url.url is an allocated string, but happens to be\nequal to normalized_url, which is freed here.\n\nPerhaps the optimal organization would be to have a\nclear_urlmatch_config() method that clears all allocated data\nwithin the config, and change things like url_normalize()\nreturn a 'const char *' to make it clear that the url should\nbe freed somewhere else.\n\nIt would help unify the handling of code that is somewhat\nduplicated (but slightly different each time) across\ncredential_apply_config(), http_init(), get_urlmatch(),\nand cmd__urlmatch_normalization().\n\nThanks,\n-Stolee\n"},{"id":"433261","messageId":"YR/sxISzR0RebVMZ@coredump.intra.peff.net","threadId":"56330","inReplyTo":"ffa1786e-f69f-3d76-98dc-7fa5cdbd31c0@gmail.com","subject":"Re: [PATCH] Fix leak in credential_apply_config","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2021-08-20T17:56:20Z","receivedAt":"2021-08-20T17:56:23Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Aug 20, 2021 at 10:58:56AM -0400, Derrick Stolee wrote:\n\n> On 8/20/2021 4:44 AM, Mike Hommey wrote:\n> >  \tnormalized_url = url_normalize(url.buf, &config.url);\n> >  \n> >  \tgit_config(urlmatch_config_entry, &config);\n> > +\tstring_list_clear(&config.vars, 1);\n> >  \tfree(normalized_url);\n> >  \tstrbuf_release(&url);\n> \n> A good find! This is obviously correct and a valuable change\n> to make. If you are interested in doing a little extra work,\n> then I think there is something more we could do here.\n> \n> I took a look at the rest of \"struct urlmatch_config\" to see\n> if anything else needed to be cleared, and it turns out that\n> config.url.url is an allocated string, but happens to be\n> equal to normalized_url, which is freed here.\n> \n> Perhaps the optimal organization would be to have a\n> clear_urlmatch_config() method that clears all allocated data\n> within the config, and change things like url_normalize()\n> return a 'const char *' to make it clear that the url should\n> be freed somewhere else.\n\nYeah, I had the same thought; it feels like we're peeking into details\nof how url_config works (especially the knowledge that we we should be\npassing free_util).\n\n> It would help unify the handling of code that is somewhat\n> duplicated (but slightly different each time) across\n> credential_apply_config(), http_init(), get_urlmatch(),\n> and cmd__urlmatch_normalization().\n\nAgreed. It looks like http_init() has the same leak that is fixed here.\n\n-Peff\n"},{"id":"433262","messageId":"YR/tETCiv3TqqEPH@coredump.intra.peff.net","threadId":"56330","inReplyTo":"YR/sxISzR0RebVMZ@coredump.intra.peff.net","subject":"Re: [PATCH] Fix leak in credential_apply_config","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2021-08-20T17:57:37Z","receivedAt":"2021-08-20T17:57:42Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Aug 20, 2021 at 01:56:20PM -0400, Jeff King wrote:\n\n> > It would help unify the handling of code that is somewhat\n> > duplicated (but slightly different each time) across\n> > credential_apply_config(), http_init(), get_urlmatch(),\n> > and cmd__urlmatch_normalization().\n> \n> Agreed. It looks like http_init() has the same leak that is fixed here.\n\nOh, nevermind. That call is indeed correct. Apparently if you re-order\ntwo lines I'm unable to see them. ;)\n\n-Peff\n"}]}