Skip to content

Commit 42a12f2

Browse files
committed
Merge pull request #3176 from Diapolo/key
fix wrong memcmp() usage in CKey::operator==
2 parents 951ed19 + a399674 commit 42a12f2

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/key.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ class CKey {
205205
}
206206

207207
friend bool operator==(const CKey &a, const CKey &b) {
208-
return a.fCompressed == b.fCompressed && memcmp(&a.vch[0], &b.vch[0], 32);
208+
return a.fCompressed == b.fCompressed && a.size() == b.size() &&
209+
memcmp(&a.vch[0], &b.vch[0], a.size()) == 0;
209210
}
210211

211212
// Initialize using begin and end iterators to byte data.
@@ -261,9 +262,9 @@ class CKey {
261262

262263
// Derive BIP32 child key.
263264
bool Derive(CKey& keyChild, unsigned char ccChild[32], unsigned int nChild, const unsigned char cc[32]) const;
264-
265+
265266
// Load private key and check that public key matches.
266-
bool Load(CPrivKey &privkey, CPubKey &vchPubKey, bool fSkipCheck);
267+
bool Load(CPrivKey &privkey, CPubKey &vchPubKey, bool fSkipCheck);
267268
};
268269

269270
struct CExtPubKey {

0 commit comments

Comments
 (0)