git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/3] revision: avoid leak when preparing bloom filter for "/"

From
Derrick Stolee <stolee@gmail.com>
Date
Aug 4, 2020, 13:09 UTC
Message-ID
<5159cfbb-55a4-8010-66a3-f6b4e4b05d7e@gmail.com>
In-Reply-To
<20200804075017.GC284046@coredump.intra.peff.net>
On 8/4/2020 3:50 AM, Jeff King wrote:
Show 21 quoted lines
> If we're given an empty pathspec, we refuse to set up bloom filters, as
> described in f3c2a36810 (revision: empty pathspecs should not use Bloom
> filters, 2020-07-01).
> 
> But before the empty string check, we drop any trailing slash by
> allocating a new string without it. So a pathspec consisting only of "/"
> will allocate that string, but then still cause us to bail, leaking the
> new string. Let's make sure to free it.
> 
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> Just noticed while reading the function to fix the previous patch.
> 
> I'm not even sure if it's possible to get here with a pathspec of "/",
> since we'd probably give a "/ is outside repository" error before then.
> 
> So maybe this case doesn't even matter. If it doesn't, then it might
> simplify the function a bit to do the empty-pathspec check before
> handling trailing slashes. But handling it does help make it more clear
> this function is doing the right thing no matter what input it is given,
> so that's what I went with here.
Works for me. Thanks for your careful attention here.
-Stolee
Show 16 quoted lines
>  revision.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/revision.c b/revision.c
> index 5ed86e4524..b80868556b 100644
> --- a/revision.c
> +++ b/revision.c
> @@ -702,6 +702,7 @@ static void prepare_to_use_bloom_filter(struct rev_info *revs)
>  	len = strlen(path);
>  	if (!len) {
>  		revs->bloom_filter_settings = NULL;
> +		free(path_alloc);
>  		return;
>  	}
>  
> 
Previous: Jeff KingNext: Taylor Blau
Message 9 of 10 in “some compiler/asan/ubsan fixes”
  1. 0/3 some compiler/asan/ubsan fixesJeff King, Aug 4, 2020
  2. 1/3 config: work around gcc-10 -Wstringop-overflow warningJeff King, Aug 4, 2020
  3. Junio C HamanoAug 4, 2020
  4. Taylor BlauAug 5, 2020
  5. 2/3 revision: avoid out-of-bounds read/write on empty pathspecJeff King, Aug 4, 2020
  6. Derrick StoleeAug 4, 2020
  7. Taylor BlauAug 5, 2020
  8. 3/3 revision: avoid leak when preparing bloom filter for "/"Jeff King, Aug 4, 2020
  9. Derrick StoleeAug 4, 2020
  10. Taylor BlauAug 5, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.