git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Taylor Blau <me@ttaylorr.com>
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>,
	Junio C Hamano <gitster@pobox.com>
Subject: Re: [PATCH 5/6] pack-bitmap-write.c: avoid uninitialized 'write_as' field
Date: Wed, 15 May 2024 11:05:10 +0200	[thread overview]
Message-ID: <ZkR6xqHgrIvoV6OR@tanuki> (raw)
In-Reply-To: <f16175295f5c786fea2d56ebffc2b9a6beb07aa0.1715716605.git.me@ttaylorr.com>

[-- Attachment #1: Type: text/plain, Size: 1596 bytes --]

On Tue, May 14, 2024 at 03:57:03PM -0400, Taylor Blau wrote:
> Prepare to free() memory associated with bitmapped_commit structs by
> zero'ing the 'write_as' field.
> 
> In ideal cases, it is fine to do something like:
> 
>     for (i = 0; i < writer->selected_nr; i++) {
>         struct bitmapped_commit *bc = &writer->selected[i];
>         if (bc->write_as != bc->bitmap)
>             ewah_free(bc->write_as);
>         ewah_free(bc->bitmap);
>     }
> 
> but if not all of the 'write_as' fields were populated (e.g., because
> the packing_data given does not form a reachability closure), then we
> may attempt to free uninitialized memory.
> 
> Guard against this by preemptively zero'ing this field just in case.
> 
> Signed-off-by: Taylor Blau <me@ttaylorr.com>
> ---
>  pack-bitmap-write.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/pack-bitmap-write.c b/pack-bitmap-write.c
> index c0087dab12..420f17c2e0 100644
> --- a/pack-bitmap-write.c
> +++ b/pack-bitmap-write.c
> @@ -112,6 +112,7 @@ static inline void push_bitmapped_commit(struct bitmap_writer *writer,
>  
>  	writer->selected[writer->selected_nr].commit = commit;
>  	writer->selected[writer->selected_nr].bitmap = NULL;
> +	writer->selected[writer->selected_nr].write_as = NULL;
>  	writer->selected[writer->selected_nr].flags = 0;

Instead of having to ensure that all fields are initialized we could
also set the whole structure to zero via `memset()`, which might be a
bit more sustainable in the future. That alone doesn't really warrant a
reroll though.

Patrick

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2024-05-15  9:05 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-14 19:56 [PATCH 0/6] pack-bitmap: various pack-bitmap-write cleanups Taylor Blau
2024-05-14 19:56 ` [PATCH 1/6] object.h: add flags allocated by pack-bitmap.h Taylor Blau
2024-05-14 19:56 ` [PATCH 2/6] pack-bitmap-write.c: move commit_positions into commit_pos fields Taylor Blau
2024-05-14 19:56 ` [PATCH 3/6] pack-bitmap: avoid use of static `bitmap_writer` Taylor Blau
2024-05-14 19:57 ` [PATCH 4/6] pack-bitmap: drop unused `max_bitmaps` parameter Taylor Blau
2024-05-14 19:57 ` [PATCH 5/6] pack-bitmap-write.c: avoid uninitialized 'write_as' field Taylor Blau
2024-05-15  9:05   ` Patrick Steinhardt [this message]
2024-05-15 13:29     ` Taylor Blau
2024-05-14 19:57 ` [PATCH 6/6] pack-bitmap: introduce `bitmap_writer_free()` Taylor Blau
2024-05-15  9:05   ` Patrick Steinhardt
2024-05-15 15:58     ` Taylor Blau
2024-05-15  6:18 ` [PATCH 0/6] pack-bitmap: various pack-bitmap-write cleanups Jeff King
2024-05-15  9:05 ` Patrick Steinhardt
2024-05-15 15:58   ` Taylor Blau

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=ZkR6xqHgrIvoV6OR@tanuki \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=me@ttaylorr.com \
    --cc=peff@peff.net \
    /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).