Skip to content

Commit a1e920a

Browse files
pcloudsgitster
authored andcommitted
index-pack: terminate object buffers with NUL
We have some tricky checks in fsck that rely on a side effect of require_end_of_header(), and would otherwise easily run outside non-NUL-terminated buffers. This is a bit brittle, so let's make sure that only NUL-terminated buffers are passed around to begin with. Jeff "Peff" King contributed the detailed analysis which call paths are involved and pointed out that we also have to patch the get_data() function in unpack-objects.c, which is what Johannes "Dscho" Schindelin implemented. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Analyzed-by: Jeff King <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7add441 commit a1e920a

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

builtin/index-pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ static void *unpack_entry_data(unsigned long offset, unsigned long size,
438438
if (type == OBJ_BLOB && size > big_file_threshold)
439439
buf = fixed_buf;
440440
else
441-
buf = xmalloc(size);
441+
buf = xmallocz(size);
442442

443443
memset(&stream, 0, sizeof(stream));
444444
git_inflate_init(&stream);
@@ -543,7 +543,7 @@ static void *unpack_data(struct object_entry *obj,
543543
git_zstream stream;
544544
int status;
545545

546-
data = xmalloc(consume ? 64*1024 : obj->size);
546+
data = xmallocz(consume ? 64*1024 : obj->size);
547547
inbuf = xmalloc((len < 64*1024) ? len : 64*1024);
548548

549549
memset(&stream, 0, sizeof(stream));

builtin/unpack-objects.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ static void use(int bytes)
9191
static void *get_data(unsigned long size)
9292
{
9393
git_zstream stream;
94-
void *buf = xmalloc(size);
94+
void *buf = xmallocz(size);
9595

9696
memset(&stream, 0, sizeof(stream));
9797

0 commit comments

Comments
 (0)