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

[PATCH v2] index-pack: terminate object buffers with NUL

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Dec 8, 2014, 14:17 UTC
Message-ID
<alpine.DEB.1.00.1412081511390.13845@s15462909.onlinehome-server.info>
In-Reply-To
<20141208112835.GA15919@lanh>
From: Duy Nguyen <pclouds@gmail.com>

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 <pclouds@gmail.com>
Analyzed-by: Jeff King <peff@peff.net>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
	On Mon, 8 Dec 2014, Duy Nguyen wrote:
	> Subject: [PATCH] index-pack: terminate object buffers with NUL
	> 
	> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
	Here is a patch that is updated with Peff's suggested
	unpack-object.c:get_data change.
	While it is not as good as Peff's analysis, I can provide an
	additional data point: the test suite passes cleanly even with
		https://github.com/dscho/git/commit/567ad592
	applied (and with 567ad592, but without below changes, at least
	t1050 does not pass).
 builtin/index-pack.c     | 4 ++--
 builtin/unpack-objects.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index a369f55..4632117 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -447,7 +447,7 @@ static void *unpack_entry_data(unsigned long offset, unsigned long size,
 	if (type == OBJ_BLOB && size > big_file_threshold)
 		buf = fixed_buf;
 	else
-		buf = xmalloc(size);
+		buf = xmallocz(size);
 
 	memset(&stream, 0, sizeof(stream));
 	git_inflate_init(&stream);
@@ -552,7 +552,7 @@ static void *unpack_data(struct object_entry *obj,
 	git_zstream stream;
 	int status;
 
-	data = xmalloc(consume ? 64*1024 : obj->size);
+	data = xmallocz(consume ? 64*1024 : obj->size);
 	inbuf = xmalloc((len < 64*1024) ? len : 64*1024);
 
 	memset(&stream, 0, sizeof(stream));
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 855d94b..ac66672 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -91,7 +91,7 @@ static void use(int bytes)
 static void *get_data(unsigned long size)
 {
 	git_zstream stream;
-	void *buf = xmalloc(size);
+	void *buf = xmallocz(size);
 
 	memset(&stream, 0, sizeof(stream));
 
-- 
1.8.4.msysgit.0.dirty
Previous: Johannes SchindelinNext: Johannes Schindelin
Message 9 of 10 in “fsck: properly bound "invalid tag name" error message”
  1. fsck: properly bound "invalid tag name" error messageJeff King, Dec 8, 2014
  2. Jeff KingDec 8, 2014
  3. Johannes SchindelinDec 8, 2014
  4. Jeff KingDec 8, 2014
  5. Duy NguyenDec 8, 2014
  6. Johannes SchindelinDec 8, 2014
  7. Jeff KingDec 8, 2014
  8. Johannes SchindelinDec 8, 2014
  9. index-pack: terminate object buffers with NULJohannes Schindelin, Dec 8, 2014
  10. Johannes SchindelinDec 8, 2014

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.