Fix crash
authorCryptoManiac <balthazar.ad@gmail.com>
Wed, 1 Dec 2021 12:34:36 +0000 (15:34 +0300)
committerCryptoManiac <balthazar.ad@gmail.com>
Wed, 1 Dec 2021 12:34:36 +0000 (15:34 +0300)
src/bignum.h
src/key.cpp

index 3d5ec4b..3730b47 100644 (file)
@@ -78,6 +78,15 @@ public:
         return (*this);
     }
 
+    CBigNum(const BIGNUM *bnp) {
+        BIGNUM *dup = BN_dup(bnp);
+        if (!dup)
+        {
+            throw bignum_error("CBigNum::CBigNum(const BIGNUM*) : BN_dup failed");
+        }
+        bn = dup;
+    }
+
     ~CBigNum()
     {
         BN_clear_free(bn);
index 2f840ae..0aaa948 100644 (file)
@@ -703,8 +703,7 @@ void CMalleablePubKey::GetVariant(CPubKey &R, CPubKey &vchPubKeyVariant)
     R = CPubKey(vchPubKey);
 
     // OpenSSL BIGNUM representation of r value
-    CBigNum bnr;
-    bnr = *(CBigNum*) EC_KEY_get0_private_key(eckey);
+    CBigNum bnr(EC_KEY_get0_private_key(eckey));
     EC_KEY_free(eckey);
 
     CPoint point;