5 #include <blockfilter.h> 39 bool LegacyParsePrechecks(
const std::string& str)
43 if (str.size() >= 1 && (
IsSpace(str[0]) ||
IsSpace(str[str.size() - 1])))
50 bool LegacyParseInt32(
const std::string& str, int32_t* out)
52 if (!LegacyParsePrechecks(str))
56 long int n = strtol(str.c_str(), &endp, 10);
57 if (out) *out = (int32_t)n;
61 return endp && *endp == 0 && !errno &&
62 n >= std::numeric_limits<int32_t>::min() &&
63 n <= std::numeric_limits<int32_t>::max();
66 bool LegacyParseInt64(
const std::string& str, int64_t* out)
68 if (!LegacyParsePrechecks(str))
72 long long int n = strtoll(str.c_str(), &endp, 10);
73 if (out) *out = (int64_t)n;
76 return endp && *endp == 0 && !errno &&
77 n >= std::numeric_limits<int64_t>::min() &&
78 n <= std::numeric_limits<int64_t>::max();
81 bool LegacyParseUInt32(
const std::string& str, uint32_t* out)
83 if (!LegacyParsePrechecks(str))
85 if (str.size() >= 1 && str[0] ==
'-')
89 unsigned long int n = strtoul(str.c_str(), &endp, 10);
90 if (out) *out = (uint32_t)n;
94 return endp && *endp == 0 && !errno &&
95 n <= std::numeric_limits<uint32_t>::max();
98 bool LegacyParseUInt8(
const std::string& str, uint8_t* out)
101 if (!LegacyParseUInt32(str, &
u32) ||
u32 > std::numeric_limits<uint8_t>::max()) {
104 if (out !=
nullptr) {
105 *out =
static_cast<uint8_t
>(
u32);
110 bool LegacyParseUInt64(
const std::string& str, uint64_t* out)
112 if (!LegacyParsePrechecks(str))
114 if (str.size() >= 1 && str[0] ==
'-')
116 char* endp =
nullptr;
118 unsigned long long int n = strtoull(str.c_str(), &endp, 10);
119 if (out) *out = (uint64_t)n;
122 return endp && *endp == 0 && !errno &&
123 n <= std::numeric_limits<uint64_t>::max();
129 return strtoll(str.c_str(),
nullptr, 10);
137 const std::string random_string_2 = fuzzed_data_provider.ConsumeRandomLengthString(32);
148 const auto width{fuzzed_data_provider.ConsumeIntegralInRange<
size_t>(1, 1000)};
149 (void)
FormatParagraph(random_string_1, width, fuzzed_data_provider.ConsumeIntegralInRange<
size_t>(0, width));
150 (void)
FormatSubVersion(random_string_1, fuzzed_data_provider.ConsumeIntegral<
int>(), random_string_vector);
157 (void)
Join(random_string_vector, random_string_1);
158 (void)
JSONRPCError(fuzzed_data_provider.ConsumeIntegral<
int>(), random_string_1);
164 }
catch (
const std::runtime_error&) {
171 }
catch (
const std::runtime_error&) {
175 }
catch (
const std::runtime_error&) {
178 (void)
SanitizeString(random_string_1, fuzzed_data_provider.ConsumeIntegralInRange<
int>(0, 3));
183 std::string host_out;
186 (void)
ToLower(random_string_1);
187 (void)
ToUpper(random_string_1);
189 (void)
TrimString(random_string_1, random_string_2);
192 (void)
_(random_string_1.c_str());
195 }
catch (
const std::runtime_error&) {
202 data_stream << random_string_1;
204 data_stream >> limited_string;
205 assert(data_stream.empty());
206 assert(s.size() <= random_string_1.size());
208 if (!random_string_1.empty()) {
211 }
catch (
const std::ios_base::failure&) {
217 data_stream << limited_string;
218 std::string deserialized_string;
219 data_stream >> deserialized_string;
220 assert(data_stream.empty());
221 assert(deserialized_string == random_string_1);
225 (void)
ParseFixedPoint(random_string_1, fuzzed_data_provider.ConsumeIntegralInRange<
int>(0, 1024), &amount_out);
228 const auto single_split{
SplitString(random_string_1, fuzzed_data_provider.ConsumeIntegral<
char>())};
229 assert(single_split.size() >= 1);
230 const auto any_split{
SplitString(random_string_1, random_string_2)};
231 assert(any_split.size() >= 1);
245 const bool ok_i32 =
ParseInt32(random_string_1, &i32);
246 const bool ok_i64 =
ParseInt64(random_string_1, &i64);
248 const bool ok_u64 =
ParseUInt64(random_string_1, &u64);
256 const bool ok_i32_legacy = LegacyParseInt32(random_string_1, &i32_legacy);
257 const bool ok_i64_legacy = LegacyParseInt64(random_string_1, &i64_legacy);
258 const bool ok_u32_legacy = LegacyParseUInt32(random_string_1, &u32_legacy);
259 const bool ok_u64_legacy = LegacyParseUInt64(random_string_1, &u64_legacy);
260 const bool ok_u8_legacy = LegacyParseUInt8(random_string_1, &u8_legacy);
262 assert(ok_i32 == ok_i32_legacy);
263 assert(ok_i64 == ok_i64_legacy);
264 assert(ok_u32 == ok_u32_legacy);
265 assert(ok_u64 == ok_u64_legacy);
266 assert(ok_u8 == ok_u8_legacy);
269 assert(i32 == i32_legacy);
272 assert(i64 == i64_legacy);
278 assert(u64 == u64_legacy);
286 const int locale_independent_atoi_result = LocaleIndependentAtoi<int>(random_string_1);
287 const int64_t atoi64_result =
atoi64_legacy(random_string_1);
288 assert(locale_independent_atoi_result == std::clamp<int64_t>(atoi64_result, std::numeric_limits<int>::min(), std::numeric_limits<int>::max()));
292 const int64_t atoi64_result =
atoi64_legacy(random_string_1);
293 const int64_t locale_independent_atoi_result = LocaleIndependentAtoi<int64_t>(random_string_1);
294 assert(atoi64_result == locale_independent_atoi_result);
std::string CopyrightHolders(const std::string &strPrefix)
bool OnlyHasDefaultSectionSetting(const Settings &settings, const std::string §ion, const std::string &name)
Return true if a setting is set in the default config file section, and not overridden by a higher pr...
bool TimingResistantEqual(const T &a, const T &b)
Timing-attack-resistant comparison.
bilingual_str ResolveErrMsg(const std::string &optname, const std::string &strBind)
std::vector< std::string > ConsumeRandomLengthStringVector(FuzzedDataProvider &fuzzed_data_provider, const size_t max_vector_size=16, const size_t max_string_length=16) noexcept
bilingual_str AmountErrMsg(const std::string &optname, const std::string &strValue)
bool BlockFilterTypeByName(const std::string &name, BlockFilterType &filter_type)
Find a filter type by its human-readable name.
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
std::string GetDescriptorChecksum(const std::string &descriptor)
Get the checksum for a descriptor.
std::string ShellEscape(const std::string &arg)
bool ParseUInt64(std::string_view str, uint64_t *out)
Convert decimal string to unsigned 64-bit integer with strict parse error feedback.
Double ended buffer combining vector and stream-like interfaces.
std::string HelpMessageGroup(const std::string &message)
Format a string to be used as group of options in help messages.
std::vector< std::string > SplitString(std::string_view str, char sep)
int64_t atoi64_legacy(const std::string &str)
UniValue RPCConvertValues(const std::string &strMethod, const std::vector< std::string > &strParams)
Convert positional arguments to command-specific RPC representation.
std::string SanitizeString(std::string_view str, int rule)
Remove unsafe chars.
std::string HelpMessageOpt(const std::string &option, const std::string &message)
Format a string to be used as option description in help messages.
bool ParseUInt32(std::string_view str, uint32_t *out)
Convert decimal string to unsigned 32-bit integer with strict parse error feedback.
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
UniValue JSONRPCError(int code, const std::string &message)
bool ContainsNoNUL(std::string_view str) noexcept
Check if a string does not contain any embedded NUL (\0) characters.
UniValue ParseNonRFCJSONValue(const std::string &strVal)
Non-RFC4627 JSON parser, accepts internal values (such as numbers, true, false, null) as well as obje...
bilingual_str _(const char *psz)
Translation function.
std::optional< OutputType > ParseOutputType(const std::string &type)
static const int INIT_PROTO_VERSION
initial proto version, to be increased after version/verack negotiation
bilingual_str AmountHighWarn(const std::string &optname)
std::string ConsumeRandomLengthString(size_t max_length)
bool ParseUInt8(std::string_view str, uint8_t *out)
Convert decimal string to unsigned 8-bit integer with strict parse error feedback.
std::string FormatParagraph(std::string_view in, size_t width, size_t indent)
Format a paragraph of text to a fixed width, adding spaces for indentation to any added line...
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
bool IsDeprecatedRPCEnabled(const std::string &method)
bool ParseFixedPoint(std::string_view val, int decimals, int64_t *amount_out)
Parse number as fixed point according to JSON number syntax.
enum Network ParseNetwork(const std::string &net_in)
std::string ToLower(std::string_view str)
Returns the lowercase equivalent of the given string.
bool ParseInt32(std::string_view str, int32_t *out)
Convert string to signed 32-bit integer with strict parse error feedback.
bool ParseInt64(std::string_view str, int64_t *out)
Convert string to signed 64-bit integer with strict parse error feedback.
auto Join(const C &container, const S &separator, UnaryOp unary_op)
Join all container items.
constexpr bool IsSpace(char c) noexcept
Tests if the given character is a whitespace character.
std::string FormatSubVersion(const std::string &name, int nClientVersion, const std::vector< std::string > &comments)
Format the subversion field according to BIP 14 spec (https://github.com/bitcoin/bips/blob/master/bip...
#define LIMITED_STRING(obj, n)
std::string RemovePrefix(std::string_view str, std::string_view prefix)
UniValue RPCConvertNamedValues(const std::string &strMethod, const std::vector< std::string > &strParams)
Convert named arguments to command-specific RPC representation.
bool FeeModeFromString(const std::string &mode_string, FeeEstimateMode &fee_estimate_mode)
std::string TrimString(std::string_view str, std::string_view pattern=" \\\)
std::string Capitalize(std::string str)
Capitalizes the first character of the given string.
std::string ToUpper(std::string_view str)
Returns the uppercase equivalent of the given string.
void SplitHostPort(std::string_view in, uint16_t &portOut, std::string &hostOut)