mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-12 04:42:36 -03:00
Merge pull request #5640
c6b7b29
Improve robustness of DER recoding code (Wladimir J. van der Laan)
This commit is contained in:
commit
8d0fd46460
1 changed files with 12 additions and 1 deletions
|
@ -124,7 +124,18 @@ bool CECKey::Verify(const uint256 &hash, const std::vector<unsigned char>& vchSi
|
||||||
unsigned char *norm_der = NULL;
|
unsigned char *norm_der = NULL;
|
||||||
ECDSA_SIG *norm_sig = ECDSA_SIG_new();
|
ECDSA_SIG *norm_sig = ECDSA_SIG_new();
|
||||||
const unsigned char* sigptr = &vchSig[0];
|
const unsigned char* sigptr = &vchSig[0];
|
||||||
d2i_ECDSA_SIG(&norm_sig, &sigptr, vchSig.size());
|
assert(norm_sig);
|
||||||
|
if (d2i_ECDSA_SIG(&norm_sig, &sigptr, vchSig.size()) == NULL)
|
||||||
|
{
|
||||||
|
/* As of OpenSSL 1.0.0p d2i_ECDSA_SIG frees and nulls the pointer on
|
||||||
|
* error. But OpenSSL's own use of this function redundantly frees the
|
||||||
|
* result. As ECDSA_SIG_free(NULL) is a no-op, and in the absence of a
|
||||||
|
* clear contract for the function behaving the same way is more
|
||||||
|
* conservative.
|
||||||
|
*/
|
||||||
|
ECDSA_SIG_free(norm_sig);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
int derlen = i2d_ECDSA_SIG(norm_sig, &norm_der);
|
int derlen = i2d_ECDSA_SIG(norm_sig, &norm_der);
|
||||||
ECDSA_SIG_free(norm_sig);
|
ECDSA_SIG_free(norm_sig);
|
||||||
if (derlen <= 0)
|
if (derlen <= 0)
|
||||||
|
|
Loading…
Reference in a new issue