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

[PATCH 07/10] fast-import.c: convert trivial snprintf calls to xsnprintf

From
Elia Pinto <gitter.spiros@gmail.com>
Date
Jun 3, 2016, 07:47 UTC
Message-ID
<20160603074724.12173-7-gitter.spiros@gmail.com>
In-Reply-To
<20160603074724.12173-1-gitter.spiros@gmail.com>

With the commits f2f02675 and 5096d490 we have been converted in some files the call from snprintf/sprintf/strcpy to xsnprintf. This patch converts the remaining calls to snprintf with xsnprintf under the following conditions:

- The call to snprintf does not control the outcome of the command
  or the presence of truncation errors.
- A call to snprintf can generate a fatal error, directly or indirectly.

The other few remaining cases in which a call to snprintf can generate a soft error have not been changed.

Signed-off-by: Elia Pinto <gitter.spiros@gmail.com>
---
 fast-import.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/fast-import.c b/fast-import.c
index 59630ce..5beb63d 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -1240,10 +1240,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.9.0.rc1.265.geb5d750
Previous: Jeff KingNext: Elia Pinto
Message 14 of 21 in “builtin/commit.c: convert trivial snprintf calls to xsnprintf”
  1. 01/10 builtin/commit.c: convert trivial snprintf calls to xsnprintfElia Pinto, Jun 3, 2016
  2. 02/10 builtin/index-pack.c: convert trivial snprintf calls to xsnprintfElia Pinto, Jun 3, 2016
  3. Jeff KingJun 3, 2016
  4. Ramsay JonesJun 3, 2016
  5. Jeff KingJun 3, 2016
  6. 03/10 builtin/tag.c: convert trivial snprintf calls to xsnprintfElia Pinto, Jun 3, 2016
  7. Jeff KingJun 3, 2016
  8. Ramsay JonesJun 3, 2016
  9. 04/10 combine-diff.c: convert trivial snprintf calls to xsnprintfElia Pinto, Jun 3, 2016
  10. Jeff KingJun 3, 2016
  11. 05/10 compat/inet_ntop.c: convert trivial snprintf calls to xsnprintfElia Pinto, Jun 3, 2016
  12. 06/10 diff.c: convert trivial snprintf calls to xsnprintfElia Pinto, Jun 3, 2016
  13. Jeff KingJun 3, 2016
  14. 07/10 fast-import.c: convert trivial snprintf calls to xsnprintfElia Pinto, Jun 3, 2016
  15. 08/10 refs.c: convert trivial snprintf calls to xsnprintfElia Pinto, Jun 3, 2016
  16. 09/10 transport-helper.c: convert trivial snprintf calls to xsnprintfElia Pinto, Jun 3, 2016
  17. 10/10 wrapper.c: convert trivial snprintf calls to xsnprintfElia Pinto, Jun 3, 2016
  18. Jeff KingJun 3, 2016
  19. Jeff KingJun 3, 2016
  20. Jeff KingJun 3, 2016
  21. Ramsay JonesJun 3, 2016

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.