aboutsummaryrefslogtreecommitdiff
path: root/src/util/string.h
diff options
context:
space:
mode:
authorpracticalswift <practicalswift@users.noreply.github.com>2019-12-11 11:00:52 +0000
committerpracticalswift <practicalswift@users.noreply.github.com>2019-12-12 11:01:56 +0000
commitd945c6f5e6f61b6e289ac7da6834c18f1b677b0f (patch)
tree59a127942a439fd1bdb344daf929a0acbdd0e0ee /src/util/string.h
parentff7a9992263f5a19f73097c86068b6150d213c23 (diff)
downloadbitcoin-d945c6f5e6f61b6e289ac7da6834c18f1b677b0f.tar.xz
util: Don't allow base58-decoding of std::string:s containing non-base58 characters
Diffstat (limited to 'src/util/string.h')
-rw-r--r--src/util/string.h11
1 files changed, 11 insertions, 0 deletions
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 <attributes.h>
+
+#include <cstring>
#include <string>
#include <vector>
@@ -31,4 +34,12 @@ inline std::string Join(const std::vector<std::string>& 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