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

[PATCH 5/6] pack-bitmap-write.c: avoid uninitialized 'write_as' field

From
Taylor Blau <me@ttaylorr.com>
Date
May 14, 2024, 19:57 UTC
Message-ID
<f16175295f5c786fea2d56ebffc2b9a6beb07aa0.1715716605.git.me@ttaylorr.com>
In-Reply-To
<cover.1715716605.git.me@ttaylorr.com>

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;
 
 	writer->selected_nr++;
-- 
2.45.1.151.g7cc3499008c
Previous: Taylor BlauNext: Patrick Steinhardt
Message 6 of 14 in “pack-bitmap: various pack-bitmap-write cleanups”
  1. 0/6 pack-bitmap: various pack-bitmap-write cleanupsTaylor Blau, May 14, 2024
  2. 1/6 object.h: add flags allocated by pack-bitmap.hTaylor Blau, May 14, 2024
  3. 2/6 pack-bitmap-write.c: move commit_positions into commit_pos fieldsTaylor Blau, May 14, 2024
  4. 3/6 pack-bitmap: avoid use of static `bitmap_writer`Taylor Blau, May 14, 2024
  5. 4/6 pack-bitmap: drop unused `max_bitmaps` parameterTaylor Blau, May 14, 2024
  6. 5/6 pack-bitmap-write.c: avoid uninitialized 'write_as' fieldTaylor Blau, May 14, 2024
  7. Patrick SteinhardtMay 15, 2024
  8. Taylor BlauMay 15, 2024
  9. 6/6 pack-bitmap: introduce `bitmap_writer_free()`Taylor Blau, May 14, 2024
  10. Patrick SteinhardtMay 15, 2024
  11. Taylor BlauMay 15, 2024
  12. Jeff KingMay 15, 2024
  13. Patrick SteinhardtMay 15, 2024
  14. Taylor BlauMay 15, 2024

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.