Skip to content

Commit 18b1850

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Acked-by: Fabian Stelzer <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7e27bd5 commit 18b1850

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

gpg-interface.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,17 +387,19 @@ static void parse_ssh_output(struct signature_check *sigc)
387387
line = to_free = xmemdupz(sigc->output, strcspn(sigc->output, "\n"));
388388

389389
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-
394390
/* Search for the last "with" to get the full principal */
395391
principal = line;
396392
do {
397393
search = strstr(line, " with ");
398394
if (search)
399395
line = search + 1;
400396
} 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;
401403
sigc->signer = xmemdupz(principal, line - principal - 1);
402404
} else if (skip_prefix(line, "Good \"git\" signature with ", &line)) {
403405
/* Valid signature, but key unknown */

0 commit comments

Comments
 (0)