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

[PATCH] git format-patch: avoid underrun when format.headers is empty or all NLs

From
Jim Meyering <jim@meyering.net>
Date
Aug 19, 2008, 13:23 UTC
Message-ID
<87iqtxyw8i.fsf@rho.meyering.net>
* builtin-log.c (add_header): Avoid a buffer underrun when
format.headers is empty or all newlines.  Reproduce with this:
git config format.headers '' && git format-patch -1
---
I spotted this via inspection.
 builtin-log.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/builtin-log.c b/builtin-log.c
index f4975cf..911fd65 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -461,7 +461,7 @@ static int extra_cc_alloc;
 static void add_header(const char *value)
 {
 	int len = strlen(value);
-	while (value[len - 1] == '\n')
+	while (len && value[len - 1] == '\n')
 		len--;
 	if (!strncasecmp(value, "to: ", 4)) {
 		ALLOC_GROW(extra_to, extra_to_nr + 1, extra_to_alloc);
--
1.6.0.4.g750768
Message 1 of 1 in “git format-patch: avoid underrun when format.headers is empty or all NLs”
  1. git format-patch: avoid underrun when format.headers is empty or all NLsJim Meyering, Aug 19, 2008

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.