Skip to content

Commit

Permalink
git-fast-import possible memory corruption problem
Browse files Browse the repository at this point in the history
Internal "allocate in bulk, we will never free this memory anyway"
allocator used in fast-import had a logic to round up the size of the
requested memory block in a wrong place (it computed if the available
space is enough to fit the request first, and then carved a chunk of
memory by size rounded up to the alignment, which could go beyond the
actually available space).

Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
YONETANI Tomokazu authored and Junio C Hamano committed Dec 15, 2008
1 parent 7e76aba commit 2fad532
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions fast-import.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,10 @@ static void *pool_alloc(size_t len)
struct mem_pool *p;
void *r;

/* round up to a 'uintmax_t' alignment */
if (len & (sizeof(uintmax_t) - 1))
len += sizeof(uintmax_t) - (len & (sizeof(uintmax_t) - 1));

for (p = mem_pool; p; p = p->next_pool)
if ((p->end - p->next_free >= len))
break;
Expand All @@ -572,9 +576,6 @@ static void *pool_alloc(size_t len)
}

r = p->next_free;
/* round out to a 'uintmax_t' alignment */
if (len & (sizeof(uintmax_t) - 1))
len += sizeof(uintmax_t) - (len & (sizeof(uintmax_t) - 1));
p->next_free += len;
return r;
}
Expand Down

0 comments on commit 2fad532

Please sign in to comment.