mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-04 10:12:28 +02:00
util: Don't allow base58-decoding of std::string:s containing non-base58 characters
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <util/strencodings.h>
|
||||
#include <util/string.h>
|
||||
|
||||
#include <tinyformat.h>
|
||||
|
||||
@@ -269,7 +270,7 @@ NODISCARD static bool ParsePrechecks(const std::string& str)
|
||||
return false;
|
||||
if (str.size() >= 1 && (IsSpace(str[0]) || IsSpace(str[str.size()-1]))) // No padding allowed
|
||||
return false;
|
||||
if (str.size() != strlen(str.c_str())) // No embedded NUL characters allowed
|
||||
if (!ValidAsCString(str)) // No embedded NUL characters allowed
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user