From a4fddb01c5bd0ecbd5e297ee571ad29ca62bf940 Mon Sep 17 00:00:00 2001 From: Vaidas Pilkauskas Date: Tue, 17 Mar 2026 13:00:34 +0000 Subject: strbuf_attach: fix call sites to pass correct alloc strbuf_attach(sb, buf, len, alloc) requires alloc > len (the buffer must have at least len+1 bytes to hold the NUL). Several call sites passed alloc == len, relying on strbuf_grow(sb, 0) inside strbuf_attach to reallocate. Fix these in mailinfo, am, refs/files-backend, fast-import, and trailer by passing len+1 when the buffer is a NUL-terminated string (or from strbuf_detach). Signed-off-by: Vaidas Pilkauskas Signed-off-by: Junio C Hamano --- trailer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'trailer.c') diff --git a/trailer.c b/trailer.c index 911a81ed99..3afe368db0 100644 --- a/trailer.c +++ b/trailer.c @@ -1009,7 +1009,7 @@ static struct trailer_block *trailer_block_get(const struct process_trailer_opti for (ptr = trailer_lines; *ptr; ptr++) { if (last && isspace((*ptr)->buf[0])) { struct strbuf sb = STRBUF_INIT; - strbuf_attach(&sb, *last, strlen(*last), strlen(*last)); + strbuf_attach(&sb, *last, strlen(*last), strlen(*last) + 1); strbuf_addbuf(&sb, *ptr); *last = strbuf_detach(&sb, NULL); continue; -- cgit v1.3-5-g9baa