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) {
* 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";
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;
/* An incorrect MAC is an unconditional Error if the key is
* unencrypted. Otherwise, it means Wrong Passphrase. */
if (cipher) {
+ error = "wrong passphrase";
ret = SSH2_WRONG_PASSPHRASE;
} else {
error = "MAC failed";