All of lore.kernel.org
 help / color / mirror / Atom feed
From: Toon Claes <toon@iotcl.com>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org, Karthik Nayak <karthik.188@gmail.com>,
	Anders Kaseorg <andersk@mit.edu>
Subject: Re: [PATCH] last-modified: fix bug caused by inproper initialized memory
Date: Mon, 08 Dec 2025 12:47:20 +0100	[thread overview]
Message-ID: <87bjk9w5yv.fsf@iotcl.com> (raw)
In-Reply-To: <20251128205514.GA605489@coredump.intra.peff.net>

Jeff King <peff@peff.net> writes:

> I think this patch makes sense as the most obvious and immediate fix.
> But thinking on how we might have avoided this bug:
>
>   - We have macros like ALLOC_ARRAY() and COPY_ARRAY() that
>     automatically multiply the array length by the size of each element
>     (by looking at the type of the array). We could in theory have a
>     helper like:
>
>       MEMSET_ARRAY(lm->scratch->words, 0x0, lm->scratch->word_alloc);
>
>     that would have made this hard to get wrong. But that's actually a
>     bit of a funny interface, because memset is inherently byte-oriented
>     under the hood. So we are not setting each element to 0x0, but
>     rather each byte. For a value of 0x0, that is the same thing. But if
>     you chose, say "0x1", it is not.
>
>     So it would probably have to be limited to something like:
>
>       CLEAR_ARRAY(lm->scratch->words, lm->scratch->word_alloc);
>
>     which I'd guess would cover most memset cases. But this is getting
>     specific enough that maybe the macro is making things more confusing
>     rather than less.

I've submitted a v2 that introduces MEMZERO_ARRAY(). I'm curious what
the responses on this proposal are?

-- 
Cheers,
Toon

  parent reply	other threads:[~2025-12-08 11:47 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-28 16:37 [PATCH] last-modified: fix bug caused by inproper initialized memory Toon Claes
2025-11-28 20:55 ` Jeff King
2025-11-28 22:20   ` Anders Kaseorg
2025-11-29 10:50     ` Jeff King
2025-12-08 11:47   ` Toon Claes [this message]
2025-12-08 20:15     ` Jeff King
2025-12-08 22:42       ` Junio C Hamano
2025-11-29  2:01 ` Junio C Hamano
2025-11-29  2:11   ` Junio C Hamano
2025-11-29  9:38     ` Toon Claes
2025-12-08 11:46 ` [PATCH v2] last-modified: fix use of uninitialized memory Toon Claes
2025-12-08 13:26   ` Junio C Hamano
2025-12-09  8:43     ` Toon Claes
2025-12-09 12:18       ` Junio C Hamano

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=87bjk9w5yv.fsf@iotcl.com \
    --to=toon@iotcl.com \
    --cc=andersk@mit.edu \
    --cc=git@vger.kernel.org \
    --cc=karthik.188@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.