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>
This commit is contained in:
parent
747e25050b
commit
b09b868f7f
13
log-tree.c
13
log-tree.c
@ -187,16 +187,11 @@ void get_patch_filename(struct commit *commit, int nr, const char *suffix,
|
|||||||
|
|
||||||
strbuf_addf(buf, commit ? "%04d-" : "%d", nr);
|
strbuf_addf(buf, commit ? "%04d-" : "%d", nr);
|
||||||
if (commit) {
|
if (commit) {
|
||||||
|
int max_len = start_len + FORMAT_PATCH_NAME_MAX - suffix_len;
|
||||||
|
|
||||||
format_commit_message(commit, "%f", buf, DATE_NORMAL);
|
format_commit_message(commit, "%f", buf, DATE_NORMAL);
|
||||||
/*
|
if (max_len < buf->len)
|
||||||
* Replace characters at the end with the suffix if the
|
strbuf_setlen(buf, max_len);
|
||||||
* 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
|
|
||||||
strbuf_addstr(buf, suffix);
|
strbuf_addstr(buf, suffix);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user