git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "René Scharfe" <l.s.r@web.de>
To: Git List <git@vger.kernel.org>
Cc: Fabian Stelzer <fs@gigacodes.de>, Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 2/2] gpg-interface: avoid buffer overrun in parse_ssh_output()
Date: Sat, 30 Oct 2021 19:07:38 +0200	[thread overview]
Message-ID: <a72ebd19-9871-f811-cd5c-72b89dad6c6f@web.de> (raw)
In-Reply-To: <f6fca7c0-079c-4337-23d9-cd970c79b8ad@web.de>

If the string "key" we found in the output of ssh-keygen happens to be
located at the very end of the line, then going four characters further
leaves us beyond the end of the string.  Explicitly search for the
space after "key" to handle a missing one gracefully.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
This code was added after v2.33.0.

 gpg-interface.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gpg-interface.c b/gpg-interface.c
index 62d340e78a..3838536f0a 100644
--- a/gpg-interface.c
+++ b/gpg-interface.c
@@ -409,9 +409,9 @@ static void parse_ssh_output(struct signature_check *sigc)
 		goto cleanup;
 	}

-	key = strstr(line, "key");
+	key = strstr(line, "key ");
 	if (key) {
-		sigc->fingerprint = xstrdup(strstr(line, "key") + 4);
+		sigc->fingerprint = xstrdup(strstr(line, "key ") + 4);
 		sigc->key = xstrdup(sigc->fingerprint);
 	} else {
 		/*
--
2.33.1


  reply	other threads:[~2021-10-30 17:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-30 17:04 [PATCH 1/2] gpg-interface: handle missing " with " gracefully in parse_ssh_output() René Scharfe
2021-10-30 17:07 ` René Scharfe [this message]
2021-11-01  6:07   ` [PATCH 2/2] gpg-interface: avoid buffer overrun " Junio C Hamano
2021-11-01  8:33   ` Fabian Stelzer
2021-11-01 17:44     ` Junio C Hamano
2021-11-01  6:08 ` [PATCH 1/2] gpg-interface: handle missing " with " gracefully " Junio C Hamano
2021-11-01  8:40 ` Fabian Stelzer
2021-11-01 18:36   ` René Scharfe

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a72ebd19-9871-f811-cd5c-72b89dad6c6f@web.de \
    --to=l.s.r@web.de \
    --cc=fs@gigacodes.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).