mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-19 09:53:47 +01:00
fuzz: call lookup functions before calling Ban
Also, compare banmaps only if there are no invalid entries.
This commit is contained in:
parent
4458ae811a
commit
f9b286353f
@ -63,17 +63,28 @@ FUZZ_TARGET(banman, .init = initialize_banman)
|
||||
// The complexity is O(N^2), where N is the input size, because each call
|
||||
// might call DumpBanlist (or other methods that are at least linear
|
||||
// complexity of the input size).
|
||||
bool contains_invalid{false};
|
||||
LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 300)
|
||||
{
|
||||
CallOneOf(
|
||||
fuzzed_data_provider,
|
||||
[&] {
|
||||
ban_man.Ban(ConsumeNetAddr(fuzzed_data_provider),
|
||||
ConsumeBanTimeOffset(fuzzed_data_provider), fuzzed_data_provider.ConsumeBool());
|
||||
CNetAddr net_addr{ConsumeNetAddr(fuzzed_data_provider)};
|
||||
const std::optional<CNetAddr>& addr{LookupHost(net_addr.ToStringAddr(), /*fAllowLookup=*/false)};
|
||||
if (addr.has_value() && addr->IsValid()) {
|
||||
net_addr = *addr;
|
||||
} else {
|
||||
contains_invalid = true;
|
||||
}
|
||||
ban_man.Ban(net_addr, ConsumeBanTimeOffset(fuzzed_data_provider), fuzzed_data_provider.ConsumeBool());
|
||||
},
|
||||
[&] {
|
||||
ban_man.Ban(ConsumeSubNet(fuzzed_data_provider),
|
||||
ConsumeBanTimeOffset(fuzzed_data_provider), fuzzed_data_provider.ConsumeBool());
|
||||
CSubNet subnet{ConsumeSubNet(fuzzed_data_provider)};
|
||||
subnet = LookupSubNet(subnet.ToString());
|
||||
if (!subnet.IsValid()) {
|
||||
contains_invalid = true;
|
||||
}
|
||||
ban_man.Ban(subnet, ConsumeBanTimeOffset(fuzzed_data_provider), fuzzed_data_provider.ConsumeBool());
|
||||
},
|
||||
[&] {
|
||||
ban_man.ClearBanned();
|
||||
@ -109,7 +120,9 @@ FUZZ_TARGET(banman, .init = initialize_banman)
|
||||
BanMan ban_man_read{banlist_file, /*client_interface=*/nullptr, /*default_ban_time=*/0};
|
||||
banmap_t banmap_read;
|
||||
ban_man_read.GetBanned(banmap_read);
|
||||
assert(banmap == banmap_read);
|
||||
if (!contains_invalid) {
|
||||
assert(banmap == banmap_read);
|
||||
}
|
||||
}
|
||||
}
|
||||
fs::remove(fs::PathToString(banlist_file + ".json"));
|
||||
|
Loading…
Reference in New Issue
Block a user