gpg-interface: handle missing " with " gracefully in parse_ssh_output()
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>
René Scharfe committed
Oct 30, 2021 at 19:04 UTC
18b18503e3b3721e0a513cbc83971a960e944c19
1 file changed
+6
-4
gpg-interface.c
+6
-4
@@ -387,10 +387,6 @@ static void parse_ssh_output(struct signature_check *sigc)
387
line = to_free = xmemdupz(sigc->output, strcspn(sigc->output, "\n"));
388
389
if (skip_prefix(line, "Good \"git\" signature for ", &line)) {
390
- /* Valid signature and known principal */
391
- sigc->result = 'G';
392
- sigc->trust_level = TRUST_FULLY;
393
-
390
/* Search for the last "with" to get the full principal */
391
principal = line;
392
do {
@@ -398,6 +394,12 @@ static void parse_ssh_output(struct signature_check *sigc)
394
if (search)
395
line = search + 1;
396
} while (search != NULL);
397
+ if (line == principal)
398
+ goto cleanup;
399
+
400
+ /* Valid signature and known principal */
401
+ sigc->result = 'G';
402
+ sigc->trust_level = TRUST_FULLY;
403
sigc->signer = xmemdupz(principal, line - principal - 1);
404
} else if (skip_prefix(line, "Good \"git\" signature with ", &line)) {
405
/* Valid signature, but key unknown */