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

Re: [PATCH] last-modified: fix bug caused by inproper initialized memory

From
Toon Claes <toon@iotcl.com>
Date
Dec 8, 2025, 11:47 UTC
Message-ID
<87bjk9w5yv.fsf@iotcl.com>
In-Reply-To
<20251128205514.GA605489@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 23 quoted lines
> 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
Previous: Jeff KingNext: Jeff King
Message 5 of 14 in “last-modified: fix bug caused by inproper initialized memory”
  1. last-modified: fix bug caused by inproper initialized memoryToon Claes, Nov 28, 2025
  2. Jeff KingNov 28, 2025
  3. Anders KaseorgNov 28, 2025
  4. Jeff KingNov 29, 2025
  5. Toon ClaesDec 8, 2025
  6. Jeff KingDec 8, 2025
  7. Junio C HamanoDec 8, 2025
  8. Junio C HamanoNov 29, 2025
  9. Junio C HamanoNov 29, 2025
  10. Toon ClaesNov 29, 2025
  11. last-modified: fix use of uninitialized memoryToon Claes, Dec 8, 2025
  12. Junio C HamanoDec 8, 2025
  13. Toon ClaesDec 9, 2025
  14. Junio C HamanoDec 9, 2025

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.