X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/putty/blobdiff_plain/dfb88efd1c9503370bee8e677bbefad6ef41df85..23159902a3ae593f9022578201125600a8da8de1:/import.c diff --git a/import.c b/import.c index 05cfdc14..bb863d77 100644 --- a/import.c +++ b/import.c @@ -321,7 +321,7 @@ static struct openssh_key *load_openssh_key(const Filename *filename, const char **errmsg_p) { struct openssh_key *ret; - FILE *fp; + FILE *fp = NULL; char *line = NULL; char *errmsg, *p; int headers_done; @@ -453,6 +453,9 @@ static struct openssh_key *load_openssh_key(const Filename *filename, line = NULL; } + fclose(fp); + fp = NULL; + if (ret->keyblob_len == 0 || !ret->keyblob) { errmsg = "key body not present"; goto error; @@ -483,6 +486,7 @@ static struct openssh_key *load_openssh_key(const Filename *filename, sfree(ret); } if (errmsg_p) *errmsg_p = errmsg; + if (fp) fclose(fp); return NULL; } @@ -588,12 +592,13 @@ struct ssh2_userkey *openssh_read(const Filename *filename, char *passphrase, p = key->keyblob; - /* Expect the SEQUENCE header. Take its absence as a failure to decrypt. */ + /* Expect the SEQUENCE header. Take its absence as a failure to + * decrypt, if the key was encrypted. */ ret = ber_read_id_len(p, key->keyblob_len, &id, &len, &flags); p += ret; if (ret < 0 || id != 16) { errmsg = "ASN.1 decoding failure"; - retval = SSH2_WRONG_PASSPHRASE; + retval = key->encrypted ? SSH2_WRONG_PASSPHRASE : NULL; goto error; } @@ -625,7 +630,7 @@ struct ssh2_userkey *openssh_read(const Filename *filename, char *passphrase, if (ret < 0 || id != 2 || key->keyblob+key->keyblob_len-p < len) { errmsg = "ASN.1 decoding failure"; - retval = SSH2_WRONG_PASSPHRASE; + retval = key->encrypted ? SSH2_WRONG_PASSPHRASE : NULL; goto error; }