From: Jeff King <peff@peff•net>
To: Toon Claes <toon@iotcl•com>
Cc: Junio C Hamano <gitster@pobox•com>,
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, 8 Dec 2025 15:15:01 -0500 [thread overview]
Message-ID: <20251208201501.GA216526@coredump.intra.peff.net> (raw)
In-Reply-To: <87bjk9w5yv.fsf@iotcl.com>
On Mon, Dec 08, 2025 at 12:47:20PM +0100, Toon Claes wrote:
> > 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?
I think it looks fine, though as Junio noted, the original is already in
next so it would have to be a patch on top.
Is such a macro worth it? I guess we'd be able to see if there are other
possible sites with something like:
git grep 'memset(.*0,.*\* \?sizeof'
that's looking for memsets of "0" that also multiply by sizeof. Looks
like there are a few:
add-patch.c: memset(hunk + 1, 0, (splittable_into - 1) * sizeof(*hunk));
builtin/last-modified.c: memset(lm->scratch->words, 0x0, lm->scratch->word_alloc * sizeof(eword_t));
compat/simple-ipc/ipc-win32.c: memset(ea, 0, NR_EA * sizeof(EXPLICIT_ACCESS));
diff-delta.c: memset(hash, 0, hsize * sizeof(*hash));
hashmap.c: memset(map->table, 0, map->tablesize * sizeof(struct hashmap_entry *));
pack-revindex.c: memset(pos, 0, BUCKETS * sizeof(*pos));
The first one is an oddball, but the other five could use it. So if we
were to do a patch adding MEMZERO_ARRAY(), it would probably make sense
to convert those spots. I'd be OK either way.
-Peff
next prev parent reply other threads:[~2025-12-08 20:15 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
2025-12-08 20:15 ` Jeff King [this message]
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=20251208201501.GA216526@coredump.intra.peff.net \
--to=peff@peff$(echo .)net \
--cc=andersk@mit$(echo .)edu \
--cc=git@vger$(echo .)kernel.org \
--cc=gitster@pobox$(echo .)com \
--cc=karthik.188@gmail$(echo .)com \
--cc=toon@iotcl$(echo .)com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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