git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] log-tree: fix patch filename computation in "git format-patch"
@ 2009-03-27  0:13 Christian Couder
  2009-03-27  4:15 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Christian Couder @ 2009-03-27  0:13 UTC (permalink / raw)
  To: Junio C Hamano, Stephen Boyd; +Cc: git

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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-03-27  7:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-27  0:13 [PATCH] log-tree: fix patch filename computation in "git format-patch" Christian Couder
2009-03-27  4:15 ` Junio C Hamano
2009-03-27  4:31   ` Stephen Boyd
2009-03-27  7:15   ` Christian Couder

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).