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

[PATCH] commit.c: ensure strchrnul() doesn't scan beyond range

From
CGChandra Pratap via GitGitGadget <gitgitgadget@gmail.com>
Date
Feb 5, 2024, 17:21 UTC
Message-ID
<pull.1652.git.1707153705840.gitgitgadget@gmail.com>
From: Chandra Pratap <chandrapratap3519@gmail.com>
Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
---
    commit.c: ensure strchrnul() doesn't scan beyond range
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1652%2FChand-ra%2Fstrchrnul-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1652/Chand-ra/strchrnul-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1652
 commit.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/commit.c b/commit.c
index ef679a0b939..a65b8e92e94 100644
--- a/commit.c
+++ b/commit.c
@@ -1743,15 +1743,9 @@ const char *find_header_mem(const char *msg, size_t len,
 	int key_len = strlen(key);
 	const char *line = msg;
 
-	/*
-	 * NEEDSWORK: It's possible for strchrnul() to scan beyond the range
-	 * given by len. However, current callers are safe because they compute
-	 * len by scanning a NUL-terminated block of memory starting at msg.
-	 * Nonetheless, it would be better to ensure the function does not look
-	 * at msg beyond the len provided by the caller.
-	 */
 	while (line && line < msg + len) {
 		const char *eol = strchrnul(line, '\n');
+		assert(eol - line <= len);
 
 		if (line == eol)
 			return NULL;

base-commit: a54a84b333adbecf7bc4483c0e36ed5878cac17b
-- 
gitgitgadget
Next: René Scharfe
Message 1 of 13 in “commit.c: ensure strchrnul() doesn't scan beyond range”
  1. commit.c: ensure strchrnul() doesn't scan beyond rangeChandra Pratap via GitGitGadget, Feb 5, 2024
  2. René ScharfeFeb 5, 2024
  3. Junio C HamanoFeb 6, 2024
  4. Jeff KingFeb 8, 2024
  5. René ScharfeFeb 8, 2024
  6. Junio C HamanoFeb 8, 2024
  7. Kyle LippincottFeb 8, 2024
  8. Jeff KingFeb 8, 2024
  9. Junio C HamanoFeb 8, 2024
  10. Kyle LippincottFeb 6, 2024
  11. commit.c: ensure find_header_mem() doesn't scan beyond given rangeChandra Pratap via GitGitGadget, Feb 7, 2024
  12. René ScharfeFeb 7, 2024
  13. Junio C HamanoFeb 7, 2024

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.