From d945c6f5e6f61b6e289ac7da6834c18f1b677b0f Mon Sep 17 00:00:00 2001 From: practicalswift Date: Wed, 11 Dec 2019 11:00:52 +0000 Subject: util: Don't allow base58-decoding of std::string:s containing non-base58 characters --- src/util/string.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/util/string.h') diff --git a/src/util/string.h b/src/util/string.h index 76a83a4949..c6fa08e5b3 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -5,6 +5,9 @@ #ifndef BITCOIN_UTIL_STRING_H #define BITCOIN_UTIL_STRING_H +#include + +#include #include #include @@ -31,4 +34,12 @@ inline std::string Join(const std::vector& list, const std::string& return Join(list, separator, [](const std::string& i) { return i; }); } +/** + * Check if a string does not contain any embedded NUL (\0) characters + */ +NODISCARD inline bool ValidAsCString(const std::string& str) noexcept +{ + return str.size() == strlen(str.c_str()); +} + #endif // BITCOIN_UTIL_STRENCODINGS_H -- cgit v1.2.3