X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/06897bd7828721c71d68f28cf2df4fca57964538..b8e3173d5169da33af5b41fa3b8e5b482bfdc6dc:/sshpubk.c diff --git a/sshpubk.c b/sshpubk.c index 923ebe9d..812a8e9a 100644 --- a/sshpubk.c +++ b/sshpubk.c @@ -71,11 +71,6 @@ static int loadrsakey_main(FILE * fp, struct RSAKey *key, int pub_only, if (i < 0) goto end; /* overran */ - if (pub_only) { - ret = 1; - goto end; - } - /* Next, the comment field. */ j = GET_32BIT(buf + i); i += 4; @@ -88,9 +83,17 @@ static int loadrsakey_main(FILE * fp, struct RSAKey *key, int pub_only, } i += j; if (commentptr) - *commentptr = comment; + *commentptr = dupstr(comment); if (key) key->comment = comment; + else + sfree(comment); + + if (pub_only) { + ret = 1; + goto end; + } + if (!key) { ret = ciphertype != 0; *error = NULL; @@ -225,7 +228,7 @@ int rsakey_encrypted(const Filename *filename, char **comment) * exponent, modulus). */ int rsakey_pubblob(const Filename *filename, void **blob, int *bloblen, - const char **errorstr) + char **commentptr, const char **errorstr) { FILE *fp; char buf[64]; @@ -250,7 +253,7 @@ int rsakey_pubblob(const Filename *filename, void **blob, int *bloblen, */ if (fgets(buf, sizeof(buf), fp) && !strcmp(buf, rsa_signature)) { memset(&key, 0, sizeof(key)); - if (loadrsakey_main(fp, &key, TRUE, NULL, NULL, &error)) { + if (loadrsakey_main(fp, &key, TRUE, commentptr, NULL, &error)) { *blob = rsa_public_blob(&key, bloblen); freersakey(&key); ret = 1;