aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorVaidas Pilkauskas <vaidas.pilkauskas@shopify.com>2026-03-17 13:00:34 +0000
committerJunio C Hamano <gitster@pobox.com>2026-03-17 09:14:19 -0700
commita4fddb01c5bd0ecbd5e297ee571ad29ca62bf940 (patch)
treef6db6091b7ab32c3c2eadcbb8ee43bb31bf4892c /builtin
parentbc6a6cf5eedb19b1b1da92ed2761ff9b1c7da627 (diff)
downloadgit-a4fddb01c5bd0ecbd5e297ee571ad29ca62bf940.tar.xz
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 <vaidas.pilkauskas@shopify.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/am.c2
-rw-r--r--builtin/fast-import.c2
2 files changed, 2 insertions, 2 deletions
diff --git a/builtin/am.c b/builtin/am.c
index b66a33d8a8..66be33ab42 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1188,7 +1188,7 @@ static void am_append_signoff(struct am_state *state)
{
struct strbuf sb = STRBUF_INIT;
- strbuf_attach(&sb, state->msg, state->msg_len, state->msg_len);
+ strbuf_attach(&sb, state->msg, state->msg_len, state->msg_len + 1);
append_signoff(&sb, 0, 0);
state->msg = strbuf_detach(&sb, &state->msg_len);
}
diff --git a/builtin/fast-import.c b/builtin/fast-import.c
index b8a7757cfd..164d8a6198 100644
--- a/builtin/fast-import.c
+++ b/builtin/fast-import.c
@@ -3246,7 +3246,7 @@ static void cat_blob(struct object_entry *oe, struct object_id *oid)
cat_blob_write("\n", 1);
if (oe && oe->pack_id == pack_id) {
last_blob.offset = oe->idx.offset;
- strbuf_attach(&last_blob.data, buf, size, size);
+ strbuf_attach(&last_blob.data, buf, size, size + 1);
last_blob.depth = oe->depth;
} else
free(buf);