Use asserts to check allocation errors in CECKey::Recover

This commit is contained in:
Jack Grigg
2016-09-30 14:17:14 +13:00
parent be9e7ce722
commit f463df0e57

View File

@@ -178,17 +178,11 @@ bool CECKey::Recover(const uint256 &hash, const unsigned char *p64, int rec)
{ {
if (rec<0 || rec>=3) if (rec<0 || rec>=3)
return false; return false;
ECDSA_SIG *sig = nullptr; ECDSA_SIG *sig = ECDSA_SIG_new();
BIGNUM *sig_r = nullptr, *sig_s = nullptr; BIGNUM *sig_r = BN_bin2bn(&p64[0], 32, nullptr);
if (!(sig = ECDSA_SIG_new()) || BIGNUM *sig_s = BN_bin2bn(&p64[32], 32, nullptr);
!(sig_r = BN_bin2bn(&p64[0], 32, nullptr)) || assert(sig && sig_r && sig_s);
!(sig_s = BN_bin2bn(&p64[32], 32, nullptr)) || assert(ECDSA_SIG_set0(sig, sig_r, sig_s));
!ECDSA_SIG_set0(sig, sig_r, sig_s)) {
ECDSA_SIG_free(sig);
BN_free(sig_r);
BN_free(sig_s);
return false;
}
bool ret = ECDSA_SIG_recover_key_GFp(pkey, sig, (unsigned char*)&hash, sizeof(hash), rec, 0) == 1; bool ret = ECDSA_SIG_recover_key_GFp(pkey, sig, (unsigned char*)&hash, sizeof(hash), rec, 0) == 1;
ECDSA_SIG_free(sig); ECDSA_SIG_free(sig);
return ret; return ret;