From d855e4cac8303ad4e34ac31cfa7634286589ce99 Mon Sep 17 00:00:00 2001 From: practicalswift Date: Mon, 17 Sep 2018 16:30:08 +0200 Subject: [PATCH] Avoid triggering undefined behaviour (std::memset(nullptr, 0, 0)) if an invalid string is passed to DecodeSecret(...) --- src/key_io.cpp | 4 +++- 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 d9980895356f3..1d53a5e074dc8 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 f0107f1361641..d55119b2662e8 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