=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ssh/ssh-keygen.c,v retrieving revision 1.405 retrieving revision 1.407 diff -u -r1.405 -r1.407 --- src/usr.bin/ssh/ssh-keygen.c 2020/04/03 02:26:56 1.405 +++ src/usr.bin/ssh/ssh-keygen.c 2020/04/20 04:43:57 1.407 @@ -1,4 +1,4 @@ -/* $OpenBSD: ssh-keygen.c,v 1.405 2020/04/03 02:26:56 djm Exp $ */ +/* $OpenBSD: ssh-keygen.c,v 1.407 2020/04/20 04:43:57 djm Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1994 Tatu Ylonen , Espoo, Finland @@ -890,22 +890,25 @@ { struct stat st; char *comment = NULL; - struct sshkey *public = NULL; + struct sshkey *privkey = NULL, *pubkey = NULL; int r; if (stat(identity_file, &st) == -1) fatal("%s: %s", path, strerror(errno)); - if ((r = sshkey_load_public(path, &public, &comment)) != 0) { + if ((r = sshkey_load_public(path, &pubkey, &comment)) != 0) debug("load public \"%s\": %s", path, ssh_err(r)); + if (pubkey == NULL || comment == NULL || *comment == '\0') { + free(comment); if ((r = sshkey_load_private(path, NULL, - &public, &comment)) != 0) { + &privkey, &comment)) != 0) debug("load private \"%s\": %s", path, ssh_err(r)); - fatal("%s is not a key file.", path); - } } + if (pubkey == NULL && privkey == NULL) + fatal("%s is not a key file.", path); - fingerprint_one_key(public, comment); - sshkey_free(public); + fingerprint_one_key(pubkey == NULL ? privkey : pubkey, comment); + sshkey_free(pubkey); + sshkey_free(privkey); free(comment); }