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

[PATCH 2/4] fast-import: use xsnprintf for formatting headers

From
Jeff King <peff@peff.net>
Date
Mar 24, 2017, 17:26 UTC
Message-ID
<20170324172624.ddqquklvam2emn24@sigill.intra.peff.net>
In-Reply-To
<20170324172246.fy5drvhzqxghu44a@sigill.intra.peff.net>

The stream_blob() function checks the return value of snprintf and dies. This is more simply done with xsnprintf (and matches the similar call in store_object).

The message the user would get is less specific, but since the point is that this _shouldn't_ ever happen, that's OK.

Signed-off-by: Jeff King <peff@peff.net>
---
 fast-import.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/fast-import.c b/fast-import.c
index 4e0f3f5dd..4a057e81f 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -1237,9 +1237,7 @@ static void stream_blob(uintmax_t len, unsigned char *sha1out, uintmax_t mark)
 	sha1file_checkpoint(pack_file, &checkpoint);
 	offset = checkpoint.offset;
 
-	hdrlen = snprintf((char *)out_buf, out_sz, "blob %" PRIuMAX, len) + 1;
-	if (out_sz <= hdrlen)
-		die("impossibly large object header");
+	hdrlen = xsnprintf((char *)out_buf, out_sz, "blob %" PRIuMAX, len) + 1;
 
 	git_SHA1_Init(&c);
 	git_SHA1_Update(&c, out_buf, hdrlen);
-- 
2.12.1.843.g1937c56c2
Previous: Jeff King
Message 5 of 5 in “a few minor buffer cleanups in fast-import”
  1. 0/4 a few minor buffer cleanups in fast-importJeff King, Mar 24, 2017
  2. 1/4 fast-import: use xsnprintf for writing sha1sJeff King, Mar 24, 2017
  3. 4/4 pack.h: define largest possible encoded object sizeJeff King, Mar 24, 2017
  4. 3/4 encode_in_pack_object_header: respect output buffer lengthJeff King, Mar 24, 2017
  5. 2/4 fast-import: use xsnprintf for formatting headersJeff King, Mar 24, 2017

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.