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

[PATCH 1/2] gpg-interface: handle missing " with " gracefully in parse_ssh_output()

From
René Scharfe <l.s.r@web.de>
Date
Oct 30, 2021, 17:04 UTC
Message-ID
<f6fca7c0-079c-4337-23d9-cd970c79b8ad@web.de>

If the output of ssh-keygen starts with "Good \"git\" signature for ", but is not followed by " with " for some reason, then parse_ssh_output() uses -1 as the len parameter of xmemdupz(), which in turn will end the program. Reject the signature and carry on instead in that case.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
This code was added after v2.33.0.
Patch formatted with --inter-hunk-context=2 for easier review.

Silly bonus question: What's the purpose of the "+ 1" and "- 1", which seem to cancel each other out?

 gpg-interface.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/gpg-interface.c b/gpg-interface.c
index 800d8caa67..62d340e78a 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -387,17 +387,19 @@ static void parse_ssh_output(struct signature_check *sigc)
 	line = to_free = xmemdupz(sigc->output, strcspn(sigc->output, "\n"));

 	if (skip_prefix(line, "Good \"git\" signature for ", &line)) {
-		/* Valid signature and known principal */
-		sigc->result = 'G';
-		sigc->trust_level = TRUST_FULLY;
-
 		/* Search for the last "with" to get the full principal */
 		principal = line;
 		do {
 			search = strstr(line, " with ");
 			if (search)
 				line = search + 1;
 		} while (search != NULL);
+		if (line == principal)
+			goto cleanup;
+
+		/* Valid signature and known principal */
+		sigc->result = 'G';
+		sigc->trust_level = TRUST_FULLY;
 		sigc->signer = xmemdupz(principal, line - principal - 1);
 	} else if (skip_prefix(line, "Good \"git\" signature with ", &line)) {
 		/* Valid signature, but key unknown */
--
2.33.1
Next: René Scharfe
Message 1 of 8 in “gpg-interface: handle missing " with " gracefully in parse_ssh_output()”
  1. 1/2 gpg-interface: handle missing " with " gracefully in parse_ssh_output()René Scharfe, Oct 30, 2021
  2. 2/2 gpg-interface: avoid buffer overrun in parse_ssh_output()René Scharfe, Oct 30, 2021
  3. Junio C HamanoNov 1, 2021
  4. Fabian StelzerNov 1, 2021
  5. Junio C HamanoNov 1, 2021
  6. Junio C HamanoNov 1, 2021
  7. Fabian StelzerNov 1, 2021
  8. René ScharfeNov 1, 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.