Does the string representation make it harder for the fuzz engine to reach coverage?
Hm, yes, perhaps an alternative to facilitate it (didnt test yet, just wondering):
0+ CSubNet subnet;
1+ CNetAddr net_addr;
2 LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 300)
3 {
4 CallOneOf(
5 fuzzed_data_provider,
6 [&] {
7- const std::string name{fuzzed_data_provider.ConsumeRandomLengthString(512)};
8- if (const std::optional<CNetAddr>& addr{LookupHost(name, /*fAllowLookup=*/false)}) {
9- ban_man.Ban(addr.value(), ConsumeBanTimeOffset(fuzzed_data_provider), fuzzed_data_provider.ConsumeBool());
10+ CSubNet new_subnet{ConsumeSubNet(fuzzed_data_provider)};
11+ if (LookupSubNet(new_subnet.ToString(), new_subnet)) {
12+ subnet = new_subnet;
13 }
14 },
15 [&] {
16- const std::string name{fuzzed_data_provider.ConsumeRandomLengthString(512)};
17- CSubNet subnet;
18- if (LookupSubNet(name, subnet)) {
19- ban_man.Ban(subnet, ConsumeBanTimeOffset(fuzzed_data_provider), fuzzed_data_provider.ConsumeBool());
20+ CNetAddr new_netaddr{ConsumeNetAddr(fuzzed_data_provider)};
21+ if (const std::optional<CNetAddr>& addr{LookupHost(new_netaddr.ToStringAddr(), /*fAllowLookup=*/false)}) {
22+ net_addr = addr.value();
23 }
24 },
25+ [&] {
26+ ban_man.Ban(net_addr, ConsumeBanTimeOffset(fuzzed_data_provider), fuzzed_data_provider.ConsumeBool());
27+ },
28+ [&] {
29+ ban_man.Ban(subnet, ConsumeBanTimeOffset(fuzzed_data_provider), fuzzed_data_provider.ConsumeBool());
30+ },
31 [&] {
32 ban_man.ClearBanned();
33 },
34 [&] {
35- ban_man.IsBanned(ConsumeNetAddr(fuzzed_data_provider));
36+ ban_man.IsBanned(net_addr);
37 },
38 [&] {
39- ban_man.IsBanned(ConsumeSubNet(fuzzed_data_provider));
40+ ban_man.IsBanned(subnet);
41 },
42 [&] {
43- ban_man.Unban(ConsumeNetAddr(fuzzed_data_provider));
44+ ban_man.Unban(net_addr);
45 },
46 [&] {
47- ban_man.Unban(ConsumeSubNet(fuzzed_data_provider));
48+ ban_man.Unban(subnet);
49 },
50 [&] {
51 banmap_t banmap;
52@@ -103,7 +110,7 @@ FUZZ_TARGET(banman, .init = initialize_banman)
53 ban_man.DumpBanlist();
54 },
55 [&] {
56- ban_man.Discourage(ConsumeNetAddr(fuzzed_data_provider));
57+ ban_man.Discourage(net_addr);
58 });
59 }