Skip to content

Commit

Permalink
Avoid triggering undefined behaviour (std::memset(nullptr, 0, 0)) if …
Browse files Browse the repository at this point in the history
…an invalid string is passed to DecodeSecret(...)
  • Loading branch information
practicalswift committed Feb 7, 2019
1 parent 1933e38 commit d855e4c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/key_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ CKey DecodeSecret(const std::string& str)
key.Set(data.begin() + privkey_prefix.size(), data.begin() + privkey_prefix.size() + 32, compressed);
}
}
memory_cleanse(data.data(), data.size());
if (!data.empty()) {
memory_cleanse(data.data(), data.size());
}
return key;
}

Expand Down
1 change: 0 additions & 1 deletion test/sanitizer_suppressions/ubsan
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ bool:wallet/wallet.cpp
float-divide-by-zero:policy/fees.cpp
float-divide-by-zero:validation.cpp
float-divide-by-zero:wallet/wallet.cpp
nonnull-attribute:support/cleanse.cpp
unsigned-integer-overflow:arith_uint256.h
unsigned-integer-overflow:basic_string.h
unsigned-integer-overflow:bench/bench.h
Expand Down

0 comments on commit d855e4c

Please sign in to comment.