27 return fuzzed_data_provider.ConsumeIntegralInRange<int64_t>(std::numeric_limits<int64_t>::min(), std::numeric_limits<int32_t>::max());
33 static const auto testing_setup = MakeNoLogFileContext<>();
50 const bool start_with_corrupted_banlist{fuzzed_data_provider.ConsumeBool()};
51 bool force_read_and_write_to_err{
false};
52 if (start_with_corrupted_banlist) {
54 fuzzed_data_provider.ConsumeRandomLengthString()));
56 force_read_and_write_to_err = fuzzed_data_provider.ConsumeBool();
57 if (force_read_and_write_to_err) {
58 banlist_file =
fs::path{
"path"} /
"to" /
"inaccessible" /
"fuzzed_banlist";
63 BanMan ban_man{banlist_file,
nullptr, ConsumeBanTimeOffset(fuzzed_data_provider)};
67 bool contains_invalid{
false};
74 if (!net_addr.IsCJDNS() || !net_addr.IsValid()) {
75 const std::optional<CNetAddr>& addr{
LookupHost(net_addr.ToStringAddr(),
false)};
76 if (addr.has_value() && addr->IsValid()) {
79 contains_invalid =
true;
82 auto ban_time_offset = ConsumeBanTimeOffset(fuzzed_data_provider);
83 auto since_unix_epoch = fuzzed_data_provider.ConsumeBool();
84 ban_man.Ban(net_addr, ban_time_offset, since_unix_epoch);
89 if (!subnet.IsValid()) {
90 contains_invalid =
true;
92 auto ban_time_offset = ConsumeBanTimeOffset(fuzzed_data_provider);
93 auto since_unix_epoch = fuzzed_data_provider.ConsumeBool();
94 ban_man.Ban(subnet, ban_time_offset, since_unix_epoch);
97 ban_man.ClearBanned();
113 ban_man.GetBanned(banmap);
116 ban_man.DumpBanlist();
122 if (!force_read_and_write_to_err) {
123 ban_man.DumpBanlist();
126 ban_man.GetBanned(banmap);
127 BanMan ban_man_read{banlist_file,
nullptr, 0};
129 ban_man_read.GetBanned(banmap_read);
130 if (!contains_invalid) {
131 assert(banmap == banmap_read);
fs::path GetDataDirNet() const
Get data directory path with appended network identifier.
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
static std::string PathToString(const path &path)
Convert path object to a byte string.
std::map< CSubNet, CBanEntry > banmap_t
CSubNet LookupSubNet(const std::string &subnet_str)
Parse and resolve a specified subnet string into the appropriate internal representation.
std::vector< CNetAddr > LookupHost(const std::string &name, unsigned int nMaxSolutions, bool fAllowLookup, DNSLookupFn dns_lookup_function)
Resolve a host string to its corresponding network addresses.
bool WriteBinaryFile(const fs::path &filename, const std::string &data)
Write contents of std::string to a file.
FUZZ_TARGET(banman,.init=initialize_banman)
static bool operator==(const CBanEntry &lhs, const CBanEntry &rhs)
CNetAddr ConsumeNetAddr(FuzzedDataProvider &fuzzed_data_provider, FastRandomContext *rand) noexcept
Create a CNetAddr.
CSubNet ConsumeSubNet(FuzzedDataProvider &fuzzed_data_provider) noexcept
int64_t ConsumeTime(FuzzedDataProvider &fuzzed_data_provider, const std::optional< int64_t > &min, const std::optional< int64_t > &max) noexcept
size_t CallOneOf(FuzzedDataProvider &fuzzed_data_provider, Callables... callables)
void SeedRandomStateForTest(SeedRand seedtype)
Seed the global RNG state for testing and log the seed value.
@ ZEROS
Seed with a compile time constant of zeros.
void SetMockTime(int64_t nMockTimeIn)
DEPRECATED Use SetMockTime with chrono type.