Skip to content

Commit d855e4c

Browse files
Avoid triggering undefined behaviour (std::memset(nullptr, 0, 0)) if an invalid string is passed to DecodeSecret(...)
1 parent 1933e38 commit d855e4c

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/key_io.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ CKey DecodeSecret(const std::string& str)
142142
key.Set(data.begin() + privkey_prefix.size(), data.begin() + privkey_prefix.size() + 32, compressed);
143143
}
144144
}
145-
memory_cleanse(data.data(), data.size());
145+
if (!data.empty()) {
146+
memory_cleanse(data.data(), data.size());
147+
}
146148
return key;
147149
}
148150

test/sanitizer_suppressions/ubsan

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ bool:wallet/wallet.cpp
44
float-divide-by-zero:policy/fees.cpp
55
float-divide-by-zero:validation.cpp
66
float-divide-by-zero:wallet/wallet.cpp
7-
nonnull-attribute:support/cleanse.cpp
87
unsigned-integer-overflow:arith_uint256.h
98
unsigned-integer-overflow:basic_string.h
109
unsigned-integer-overflow:bench/bench.h

0 commit comments

Comments
 (0)