Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2023-02-16 13:29:48 +0300
committerJunio C Hamano <gitster@pobox.com>2023-02-21 20:15:04 +0300
commit6eb095d78790d0d6cbad2186685dad4e7ba2e3de (patch)
treedf35bec5a0cd400748d759ade135b07fd0661207 /delta-islands.c
parent647982bb7171b2409f2a90da245b8a31913f930f (diff)
delta-islands: fix segfault when freeing island marks
In 647982bb71 (delta-islands: free island_marks and bitmaps, 2023-02-03) we have introduced logic to free `island_marks` in order to reduce heap memory usage in git-pack-objects(1). This commit is causing segfaults in the case where this Git command does not load delta islands at all, e.g. when reading object IDs from standard input. One such crash can be hit when using repacking multi-pack-indices with delta islands enabled. The root cause of this bug is that we unconditionally dereference the `island_marks` variable even in the case where it is a `NULL` pointer, which is fixed by making it conditional. Note that we still leave the logic in place to set the pointer to `-1` to detect use-after-free bugs even when there are no loaded island marks at all. Signed-off-by: Patrick Steinhardt <ps@pks.im> Acked-by: Eric Wong <e@80x24.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'delta-islands.c')
-rw-r--r--delta-islands.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/delta-islands.c b/delta-islands.c
index 8b234cb85b..afdec0a878 100644
--- a/delta-islands.c
+++ b/delta-islands.c
@@ -517,11 +517,13 @@ void free_island_marks(void)
{
struct island_bitmap *bitmap;
- kh_foreach_value(island_marks, bitmap, {
- if (!--bitmap->refcount)
- free(bitmap);
- });
- kh_destroy_oid_map(island_marks);
+ if (island_marks) {
+ kh_foreach_value(island_marks, bitmap, {
+ if (!--bitmap->refcount)
+ free(bitmap);
+ });
+ kh_destroy_oid_map(island_marks);
+ }
/* detect use-after-free with a an address which is never valid: */
island_marks = (void *)-1;