]> Kevux Git Server - rit/commitdiff
gpg-interface: avoid buffer overrun in parse_ssh_output()
authorRené Scharfe <l.s.r@web.de>
Sat, 30 Oct 2021 17:07:38 +0000 (19:07 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 2 Nov 2021 00:00:41 +0000 (17:00 -0700)
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>
Acked-by: Fabian Stelzer <fs@gigacodes.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
gpg-interface.c

index 62d340e..3838536 100644 (file)
@@ -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 {
                /*