Skip to content

Commit b09b868

Browse files
chriscoolgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 747e250 commit b09b868

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

log-tree.c

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,12 @@ void get_patch_filename(struct commit *commit, int nr, const char *suffix,
187187

188188
strbuf_addf(buf, commit ? "%04d-" : "%d", nr);
189189
if (commit) {
190+
int max_len = start_len + FORMAT_PATCH_NAME_MAX - suffix_len;
191+
190192
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);
201196
}
202197
}
203198

0 commit comments

Comments
 (0)