summaryrefslogtreecommitdiff
path: root/fmt-merge-msg.c
diff options
context:
space:
mode:
authorTaylor Blau <me@ttaylorr.com>2022-01-10 21:19:06 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-01-10 21:57:40 (GMT)
commitc39fc06b999305963600358f3f5e99698440cad2 (patch)
tree8922bfefdecceae105da420f3c74fabb4cc887d5 /fmt-merge-msg.c
parent50992f96c546ebdc0c149660f6baa948739888d9 (diff)
downloadgit-c39fc06b999305963600358f3f5e99698440cad2.zip
git-c39fc06b999305963600358f3f5e99698440cad2.tar.gz
git-c39fc06b999305963600358f3f5e99698440cad2.tar.bz2
fmt-merge-msg: prevent use-after-free with signed tags
When merging a signed tag, fmt_merge_msg_sigs() is responsible for populating the body of the merge message with the names of the signed tags, their signatures, and the validity of those signatures. In 02769437e1 (ssh signing: use sigc struct to pass payload, 2021-12-09), check_signature() was taught to pass the object payload via the sigc struct instead of passing the payload buffer separately. In effect, 02769437e1 causes buf, and sigc.payload to point at the same region in memory. This causes a problem for fmt_tag_signature(), which wants to read from this location, since it is freed beforehand by signature_check_clear() (which frees it via sigc's `payload` member). That makes the subsequent use in fmt_tag_signature() a use-after-free. As a result, merge messages did not contain the body of any signed tags. Luckily, they tend not to contain garbage, either, since the result of strstr()-ing the object buffer in fmt_tag_signature() is guarded: const char *tag_body = strstr(buf, "\n\n"); if (tag_body) { tag_body += 2; strbuf_add(tagbuf, tag_body, buf + len - tag_body); } Unfortunately, the tests in t6200 did not catch this at the time because they do not search for the body of signed tags in fmt-merge-msg's output. Resolve this by waiting to call signature_check_clear() until after its contents can be safely discarded. Harden ourselves against any future regressions in this area by making sure we can find signed tag messages in the output of fmt-merge-msg, too. Reported-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'fmt-merge-msg.c')
-rw-r--r--fmt-merge-msg.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/fmt-merge-msg.c b/fmt-merge-msg.c
index e4f7810..422bd0c 100644
--- a/fmt-merge-msg.c
+++ b/fmt-merge-msg.c
@@ -541,7 +541,6 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
else
strbuf_addstr(&sig, sigc.output);
}
- signature_check_clear(&sigc);
if (!tag_number++) {
fmt_tag_signature(&tagbuf, &sig, buf, len);
@@ -565,6 +564,7 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
}
strbuf_release(&payload);
strbuf_release(&sig);
+ signature_check_clear(&sigc);
next:
free(origbuf);
}