Skip to content

Commit

Permalink
Merge bitcoin#14242: Avoid triggering undefined behaviour (std::memse…
Browse files Browse the repository at this point in the history
…t(nullptr, 0, 0)) if an invalid string is passed to DecodeSecret(...)

d855e4c Avoid triggering undefined behaviour (std::memset(nullptr, 0, 0)) if an invalid string is passed to DecodeSecret(...) (practicalswift)

Pull request description:

  Avoid triggering undefined behaviour (`std::memset(nullptr, 0, 0)`) if an invalid string is passed to `DecodeSecret(...)`.

  Background reading: [memcpy (and friends) with NULL pointers](https://www.imperialviolet.org/2016/06/26/nonnull.html)

  Steps to reproduce:

  ```
  ./configure --with-sanitizers=undefined && make check && ./test/functional/test_runner.py
  ```

Tree-SHA512: b8325ced4f724d9c03065e0747af56b1f297a90d9fb09a24d46c3231a90dce3df6299f2c41f863b5cec18eaeded7b46ee4b93d9a52adc2541eb4c44d2c0965d9
  • Loading branch information
laanwj authored and pravblockc committed Aug 17, 2021
1 parent 4793bbd commit 9341b3c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
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 @@ std::string EncodeExtKey(const CExtKey& key)
data.resize(size + BIP32_EXTKEY_SIZE);
key.Encode(data.data() + size);
std::string ret = EncodeBase58Check(data);
memory_cleanse(data.data(), data.size());
if (!data.empty()) {
memory_cleanse(data.data(), data.size());
}
return ret;
}

Expand Down
Empty file.

0 comments on commit 9341b3c

Please sign in to comment.