Skip to content

Commit

Permalink
fix wrong memcmp() usage in CKey::operator==
Browse files Browse the repository at this point in the history
- add a check for CKey::size() of a and b (size can be 0 or 32)
- change the fixed value in memcmp() to use a.size() instead
- fixes #3090
  • Loading branch information
Philip Kaufmann committed Oct 28, 2013
1 parent 377cd74 commit a399674
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/key.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ class CKey {
}

friend bool operator==(const CKey &a, const CKey &b) {
return a.fCompressed == b.fCompressed && memcmp(&a.vch[0], &b.vch[0], 32);
return a.fCompressed == b.fCompressed && a.size() == b.size() &&
memcmp(&a.vch[0], &b.vch[0], a.size()) == 0;
}

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

// Derive BIP32 child key.
bool Derive(CKey& keyChild, unsigned char ccChild[32], unsigned int nChild, const unsigned char cc[32]) const;

// Load private key and check that public key matches.
bool Load(CPrivKey &privkey, CPubKey &vchPubKey, bool fSkipCheck);
bool Load(CPrivKey &privkey, CPubKey &vchPubKey, bool fSkipCheck);
};

struct CExtPubKey {
Expand Down

0 comments on commit a399674

Please sign in to comment.