@matheusbsbs / matheus-bagliano / commits / b09b868f7f
Fork 0

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

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. [jc: w/ simplified logic] Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Mar 27, 2009 at 01:13 UTC b09b868f7fee689483d00bea3d52c0f14a80386c
1 file changed +5 -10
log-tree.c
+5 -10
@@ -187,17 +187,12 @@ void get_patch_filename(struct commit *commit, int nr, const char *suffix,
187
188 strbuf_addf(buf, commit ? "%04d-" : "%d", nr);
189 if (commit) {
190 + int max_len = start_len + FORMAT_PATCH_NAME_MAX - suffix_len;
191 +
192 format_commit_message(commit, "%f", buf, DATE_NORMAL);
191 - /*
192 - * Replace characters at the end with the suffix if the
193 - * filename is too long
194 - */
195 - if (buf->len + suffix_len > FORMAT_PATCH_NAME_MAX + start_len)
196 - strbuf_splice(buf,
197 - start_len + FORMAT_PATCH_NAME_MAX - suffix_len,
198 - suffix_len, suffix, suffix_len);
199 - else
200 - strbuf_addstr(buf, suffix);
193 + if (max_len < buf->len)
194 + strbuf_setlen(buf, max_len);
195 + strbuf_addstr(buf, suffix);
196 }
197 }
198