Skip to content

Commit e890c84

Browse files
committed
Merge branch 'rs/ssh-signing-fix'
Fixes to recently merged topic. * rs/ssh-signing-fix: gpg-interface: avoid buffer overrun in parse_ssh_output() gpg-interface: handle missing " with " gracefully in parse_ssh_output()
2 parents 0cddd84 + 65db97b commit e890c84

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

gpg-interface.c

Lines changed: 8 additions & 6 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 */
@@ -407,9 +409,9 @@ static void parse_ssh_output(struct signature_check *sigc)
407409
goto cleanup;
408410
}
409411

410-
key = strstr(line, "key");
412+
key = strstr(line, "key ");
411413
if (key) {
412-
sigc->fingerprint = xstrdup(strstr(line, "key") + 4);
414+
sigc->fingerprint = xstrdup(strstr(line, "key ") + 4);
413415
sigc->key = xstrdup(sigc->fingerprint);
414416
} else {
415417
/*

0 commit comments

Comments
 (0)