aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/key.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/key.cpp b/src/key.cpp
index 7fcb17d574..2b25308fe5 100644
--- a/src/key.cpp
+++ b/src/key.cpp
@@ -383,7 +383,18 @@ bool CKey::Verify(uint256 hash, const std::vector<unsigned char>& 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)