git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 4/5] ref-filter: hoist signature parsing

From
brian m. carlson <sandals@crustytoothpaste.net>
Date
Jan 11, 2021, 03:58 UTC
Message-ID
<20210111035840.2437737-5-sandals@crustytoothpaste.net>
In-Reply-To
<20210111035840.2437737-1-sandals@crustytoothpaste.net>

When we parse a signature in the ref-filter code, we continually increment the buffer pointer. Hoist the signature parsing above the blank line delimiting headers and body so we can find the signature when using a header to sign the buffer.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 ref-filter.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/ref-filter.c b/ref-filter.c
index 8d8baec1b5..32ed4d5111 100644
--- a/ref-filter.c
+++ b/ref-filter.c
@@ -1221,6 +1221,8 @@ static void find_subpos(const char *buf,
 	const char *end = buf + strlen(buf);
 	const char *sigstart;
 
+	/* parse signature first; we might not even have a subject line */
+	parse_signature(buf, end - buf, &payload, &signature);
 
 	/* skip past header until we hit empty line */
 	while (*buf && *buf != '\n') {
@@ -1232,9 +1234,6 @@ static void find_subpos(const char *buf,
 	/* skip any empty lines */
 	while (*buf == '\n')
 		buf++;
-
-	/* parse signature first; we might not even have a subject line */
-	parse_signature(buf, end - buf, &payload, &signature);
 	*sig = strbuf_detach(&signature, siglen);
 	sigstart = buf + parse_signed_buffer(buf, strlen(buf));
 
@@ -1330,7 +1329,7 @@ static void grab_sub_body_contents(struct atom_value *val, int deref, void *buf)
 			v->s = xmemdupz(sigpos, siglen);
 		else if (atom->u.contents.option == C_LINES) {
 			struct strbuf s = STRBUF_INIT;
-			const char *contents_end = bodylen + bodypos - siglen;
+			const char *contents_end = bodypos + nonsiglen;
 
 			/*  Size is the length of the message after removing the signature */
 			append_lines(&s, subpos, contents_end - subpos, atom->u.contents.nlines);
Previous: brian m. carlsonNext: brian m. carlson
Message 15 of 39 in “Support for commits signed by multiple algorithms”
  1. 0/5 Support for commits signed by multiple algorithmsbrian m. carlson, Jan 11, 2021
  2. 1/5 commit: ignore additional signatures when parsing signed commitsbrian m. carlson, Jan 11, 2021
  3. 3/5 commit: allow parsing arbitrary buffers with headersbrian m. carlson, Jan 11, 2021
  4. 2/5 gpg-interface: improve interface for parsing tagsbrian m. carlson, Jan 11, 2021
  5. Junio C HamanoJan 12, 2021
  6. brian m. carlsonJan 14, 2021
  7. Junio C HamanoJan 15, 2021
  8. 4/5 ref-filter: hoist signature parsingbrian m. carlson, Jan 11, 2021
  9. 5/6 fixup! commit: ignore additional signatures when parsing signed commitsbrian m. carlson, Jan 11, 2021
  10. brian m. carlsonJan 11, 2021
  11. 5/5 gpg-interface: remove other signature headers before verifyingbrian m. carlson, Jan 11, 2021
  12. 6/6 gpg-interface: remove other signature headers before verifyingbrian m. carlson, Jan 11, 2021
  13. 0/5 Support for commits signed by multiple algorithmsbrian m. carlson, Jan 11, 2021
  14. 3/5 commit: allow parsing arbitrary buffers with headersbrian m. carlson, Jan 11, 2021
  15. 4/5 ref-filter: hoist signature parsingbrian m. carlson, Jan 11, 2021
  16. 2/5 gpg-interface: improve interface for parsing tagsbrian m. carlson, Jan 11, 2021
  17. Junio C HamanoJan 12, 2021
  18. 5/5 gpg-interface: remove other signature headers before verifyingbrian m. carlson, Jan 11, 2021
  19. 1/5 commit: ignore additional signatures when parsing signed commitsbrian m. carlson, Jan 11, 2021
  20. SZEDER GáborJan 12, 2021
  21. Junio C HamanoJan 11, 2021
  22. brian m. carlsonJan 11, 2021
  23. Junio C HamanoJan 12, 2021
  24. brian m. carlsonJan 12, 2021
  25. 0/6 Support for commits signed by multiple algorithmsbrian m. carlson, Jan 18, 2021
  26. 1/6 ref-filter: switch some uses of unsigned long to size_tbrian m. carlson, Jan 18, 2021
  27. 2/6 commit: ignore additional signatures when parsing signed commitsbrian m. carlson, Jan 18, 2021
  28. 4/6 commit: allow parsing arbitrary buffers with headersbrian m. carlson, Jan 18, 2021
  29. 3/6 gpg-interface: improve interface for parsing tagsbrian m. carlson, Jan 18, 2021
  30. 6/6 gpg-interface: remove other signature headers before verifyingbrian m. carlson, Jan 18, 2021
  31. 5/6 ref-filter: hoist signature parsingbrian m. carlson, Jan 18, 2021
  32. 0/6 Support for commits signed by multiple algorithmsbrian m. carlson, Feb 11, 2021
  33. 4/6 commit: allow parsing arbitrary buffers with headersbrian m. carlson, Feb 11, 2021
  34. 1/6 ref-filter: switch some uses of unsigned long to size_tbrian m. carlson, Feb 11, 2021
  35. 2/6 commit: ignore additional signatures when parsing signed commitsbrian m. carlson, Feb 11, 2021
  36. 3/6 gpg-interface: improve interface for parsing tagsbrian m. carlson, Feb 11, 2021
  37. 5/6 ref-filter: hoist signature parsingbrian m. carlson, Feb 11, 2021
  38. 6/6 gpg-interface: remove other signature headers before verifyingbrian m. carlson, Feb 11, 2021
  39. Junio C HamanoFeb 11, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.