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

[PATCH] log-tree: fix patch filename computation in "git format-patch"

From
Christian Couder <chriscool@tuxfamily.org>
Date
Mar 27, 2009, 00:13 UTC
Message-ID
<20090327011301.a5185805.chriscool@tuxfamily.org>

When using "git format-patch", "get_patch_filename" in "log-tree.c" calls "strbuf_splice" that could die with the following message:

"`pos + len' is too far after the end of the buffer"
if you have:
	buf->len < start_len + FORMAT_PATCH_NAME_MAX
but:
	buf->len + suffix_len > start_len + FORMAT_PATCH_NAME_MAX
This patch tries to get rid of that bug.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 log-tree.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)
This bug happens on "pu".
diff --git a/log-tree.c b/log-tree.c
index 56a3488..ade79ab 100644
--- a/log-tree.c
+++ b/log-tree.c
@@ -187,16 +187,17 @@ void get_patch_filename(struct commit *commit, int nr, const char *suffix,
 
 	strbuf_addf(buf, commit ? "%04d-" : "%d", nr);
 	if (commit) {
+		int max_len = start_len + FORMAT_PATCH_NAME_MAX;
 		format_commit_message(commit, "%f", buf, DATE_NORMAL);
 		/*
 		 * Replace characters at the end with the suffix if the
 		 * filename is too long
 		 */
-		if (buf->len + suffix_len > FORMAT_PATCH_NAME_MAX + start_len)
-			strbuf_splice(buf,
-				start_len + FORMAT_PATCH_NAME_MAX - suffix_len,
-				suffix_len, suffix, suffix_len);
-		else
+		if (buf->len + suffix_len > max_len) {
+			int base = (max_len > buf->len) ? buf->len : max_len;
+			strbuf_splice(buf, base - suffix_len, suffix_len,
+				      suffix, suffix_len);
+		} else
 			strbuf_addstr(buf, suffix);
 	}
 }
-- 
1.6.2.1.506.g7aa09
Next: Junio C Hamano
Message 1 of 4 in “log-tree: fix patch filename computation in "git format-patch"”
  1. log-tree: fix patch filename computation in "git format-patch"Christian Couder, Mar 27, 2009
  2. Junio C HamanoMar 27, 2009
  3. Stephen BoydMar 27, 2009
  4. Christian CouderMar 27, 2009

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.