Skip to content

Commit

Permalink
Ensure that non-hex characters are caught in address checksumming
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Oct 20, 2017
1 parent 0702f7d commit ad54a55
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion libdevcore/CommonData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,13 @@ string dev::getChecksummedAddress(string const& _addr)
{
string s = _addr.substr(0, 2) == "0x" ? _addr.substr(2) : _addr;
h256 hash = keccak256(boost::algorithm::to_lower_copy(s, std::locale::classic()));

assertThrow(s.length == 40, "");
assertThrow(hash.find_first_not_of("abcdef") == string::npos, "");

string ret = "0x";

for (size_t i = 0; i < s.length(); ++i)
for (size_t i = 0; i < 40; ++i)
{
char addressCharacter = s[i];
unsigned nibble = (unsigned(hash[i / 2]) >> (4 * (1 - (i % 2)))) & 0xf;
Expand Down

0 comments on commit ad54a55

Please sign in to comment.