diff options
| author | Wladimir J. van der Laan <[email protected]> | 2019-02-08 11:41:39 +0100 |
|---|---|---|
| committer | Wladimir J. van der Laan <[email protected]> | 2019-02-08 12:30:21 +0100 |
| commit | 6fc656a410b6fa469be258414f1e26cd4b6025af (patch) | |
| tree | 4813191e90ece4956a1e0c95ff459cb2cf1b142a | |
| parent | Merge #14897: randomize GETDATA(tx) request order and introduce bias toward o... (diff) | |
| parent | Avoid triggering undefined behaviour (std::memset(nullptr, 0, 0)) if an inval... (diff) | |
| download | discoin-6fc656a410b6fa469be258414f1e26cd4b6025af.tar.xz discoin-6fc656a410b6fa469be258414f1e26cd4b6025af.zip | |
Merge #14242: Avoid triggering undefined behaviour (std::memset(nullptr, 0, 0)) if an invalid string is passed to DecodeSecret(...)
d855e4cac8303ad4e34ac31cfa7634286589ce99 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
| -rw-r--r-- | src/key_io.cpp | 4 | ||||
| -rw-r--r-- | test/sanitizer_suppressions/ubsan | 1 |
2 files changed, 3 insertions, 2 deletions
diff --git a/src/key_io.cpp b/src/key_io.cpp index d99808953..1d53a5e07 100644 --- a/src/key_io.cpp +++ b/src/key_io.cpp @@ -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; } diff --git a/test/sanitizer_suppressions/ubsan b/test/sanitizer_suppressions/ubsan index f0107f136..d55119b26 100644 --- a/test/sanitizer_suppressions/ubsan +++ b/test/sanitizer_suppressions/ubsan @@ -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 |