]> git.ipfire.org Git - thirdparty/git.git/commitdiff
gpg-interface: handle missing " with " gracefully in parse_ssh_output()
authorRené Scharfe <l.s.r@web.de>
Sat, 30 Oct 2021 17:04:56 +0000 (19:04 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 2 Nov 2021 00:00:41 +0000 (17:00 -0700)
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>
Acked-by: Fabian Stelzer <fs@gigacodes.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
gpg-interface.c

index 800d8caa677d4d2baf4fcd3c8aebf9649650a8b3..62d340e78a451633cef9fda63b5dc26debb210f0 100644 (file)
@@ -387,10 +387,6 @@ 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 {
@@ -398,6 +394,12 @@ static void parse_ssh_output(struct signature_check *sigc)
                        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 */