X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/b81cca98c2709d60a25ec96b0871d26b62e35d0a..70637309a61321d83a4d0576b875b7dcb7085fa5:/sshpubk.c diff --git a/sshpubk.c b/sshpubk.c index 26baa431..9e89fe97 100644 --- a/sshpubk.c +++ b/sshpubk.c @@ -79,8 +79,8 @@ static int loadrsakey_main(FILE * fp, struct RSAKey *key, int pub_only, i += 4; /* Now the serious stuff. An ordinary SSH 1 public key. */ - i += makekey(buf + i, key, NULL, 1); - if (len - i < 0) + i += makekey(buf + i, len, key, NULL, 1); + if (i < 0) goto end; /* overran */ if (pub_only) { @@ -138,18 +138,18 @@ static int loadrsakey_main(FILE * fp, struct RSAKey *key, int pub_only, * decryption exponent, and then the three auxiliary values * (iqmp, q, p). */ - i += makeprivate(buf + i, key); - if (len - i < 0) - goto end; - i += ssh1_read_bignum(buf + i, &key->iqmp); - if (len - i < 0) - goto end; - i += ssh1_read_bignum(buf + i, &key->q); - if (len - i < 0) - goto end; - i += ssh1_read_bignum(buf + i, &key->p); - if (len - i < 0) - goto end; + j = makeprivate(buf + i, len - i, key); + if (j < 0) goto end; + i += j; + j = ssh1_read_bignum(buf + i, len - i, &key->iqmp); + if (j < 0) goto end; + i += j; + j = ssh1_read_bignum(buf + i, len - i, &key->q); + if (j < 0) goto end; + i += j; + j = ssh1_read_bignum(buf + i, len - i, &key->p); + if (j < 0) goto end; + i += j; if (!rsa_verify(key)) { *error = "rsa_verify failed"; @@ -376,7 +376,8 @@ int saversakey(const Filename *filename, struct RSAKey *key, char *passphrase) fp = f_open(*filename, "wb"); if (fp) { int ret = (fwrite(buf, 1, p - buf, fp) == (size_t) (p - buf)); - ret = ret && (fclose(fp) == 0); + if (fclose(fp)) + ret = 0; return ret; } else return 0;