Skip to content

Commit

Permalink
Fix invalid signature with crafted length
Browse files Browse the repository at this point in the history
  • Loading branch information
noise23 committed Nov 12, 2015
1 parent 56facb0 commit ab206d0
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,24 @@ class CECKey {
return true;
}

bool Verify(const uint256 &hash, const std::vector<unsigned char>& vchSig) {
bool Verify(const uint256 &hash, const std::vector<unsigned char>& vchSigParam)
{
// Prevent the problem described here: https://lists.linuxfoundation.org/pipermail/bitcoin-dev/2015-July/009697.html
// by removing the extra length bytes
std::vector<unsigned char> vchSig(vchSigParam.begin(), vchSigParam.end());
if (vchSig.size() > 1 && vchSig[1] & 0x80)
{
unsigned char nLengthBytes = vchSig[1] & 0x7f;
if (nLengthBytes > 4)
{
unsigned char nExtraBytes = nLengthBytes - 4;
for (unsigned char i = 0; i < nExtraBytes; i++)
if (vchSig[2 + i])
return false;
vchSig.erase(vchSig.begin() + 2, vchSig.begin() + 2 + nExtraBytes);
vchSig[1] = 0x80 | (nLengthBytes - nExtraBytes);
}
}
if (vchSig.empty())
return false;
// New versions of OpenSSL will reject non-canonical DER signatures. de/re-serialize first.
Expand Down

0 comments on commit ab206d0

Please sign in to comment.