]> git.ipfire.org Git - thirdparty/git.git/commitdiff
last-modified: fix use of uninitialized memory
authorToon Claes <toon@iotcl.com>
Fri, 28 Nov 2025 16:37:13 +0000 (17:37 +0100)
committerJunio C Hamano <gitster@pobox.com>
Sat, 29 Nov 2025 22:16:53 +0000 (14:16 -0800)
git-last-modified(1) uses a scratch bitmap to keep track of paths that
have been changed between commits. To avoid reallocating a bitmap on
each call of process_parent(), the scratch bitmap is kept and reused.
Although, it seems an incorrect length is passed to memset(3).

`struct bitmap` uses `eword_t` to for internal storage. This type is
typedef'd to uint64_t. To fully zero the memory used by the bitmap,
multiply the length (saved in `struct bitmap::word_alloc`) by the size
of `eword_t`.

Reported-by: Anders Kaseorg <andersk@mit.edu>
Helped-by: Jeff King <peff@peff.net>
Signed-off-by: Toon Claes <toon@iotcl.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/last-modified.c

index b0ecbdc5400d137b7e147c8f91f43210cf8236e0..cc5fd2e7950be746443faae831c36aa9fd09e0d5 100644 (file)
@@ -327,7 +327,7 @@ static void process_parent(struct last_modified *lm,
        if (!(parent->object.flags & PARENT1))
                active_paths_free(lm, parent);
 
-       memset(lm->scratch->words, 0x0, lm->scratch->word_alloc);
+       memset(lm->scratch->words, 0x0, lm->scratch->word_alloc * sizeof(eword_t));
        diff_queue_clear(&diff_queued_diff);
 }