From: fsb4000 Date: Tue, 13 Jan 2015 12:03:08 +0000 (+0600) Subject: Improve robustness of DER recoding code X-Git-Tag: nvc-v0.5.1~1^2~1 X-Git-Url: https://git.novaco.in/?p=novacoin.git;a=commitdiff_plain;h=488efc3aee9eae2c6dcdc181305e0c9d80eb3c13 Improve robustness of DER recoding code как в https://github.com/bitcoin/bitcoin/commit/8d0fd4646099132f0a68d6c3d0da3a6a10ab9631 --- diff --git a/src/key.cpp b/src/key.cpp index 1b3f380..c37ad83 100644 --- a/src/key.cpp +++ b/src/key.cpp @@ -456,7 +456,18 @@ bool CKey::Verify(uint256 hash, const std::vector& vchSig) unsigned char *norm_der = NULL; ECDSA_SIG *norm_sig = ECDSA_SIG_new(); 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); ECDSA_SIG_free(norm_sig); if (derlen <= 0)