fuzz: add target for local addresses

This commit is contained in:
brunoerg 2024-02-26 18:06:19 -03:00
parent 4d7d7fd123
commit 25eab52389

View file

@ -77,3 +77,40 @@ FUZZ_TARGET(net, .init = initialize_net)
(void)node.HasPermission(net_permission_flags);
(void)node.ConnectedThroughNetwork();
}
FUZZ_TARGET(local_address, .init = initialize_net)
{
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
CService service{ConsumeService(fuzzed_data_provider)};
CNode node{ConsumeNode(fuzzed_data_provider)};
{
LOCK(g_maplocalhost_mutex);
mapLocalHost.clear();
}
LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
CallOneOf(
fuzzed_data_provider,
[&] {
service = ConsumeService(fuzzed_data_provider);
},
[&] {
const bool added{AddLocal(service, fuzzed_data_provider.ConsumeIntegralInRange<int>(0, LOCAL_MAX - 1))};
if (!added) return;
assert(service.IsRoutable());
assert(IsLocal(service));
assert(SeenLocal(service));
},
[&] {
(void)RemoveLocal(service);
},
[&] {
(void)SeenLocal(service);
},
[&] {
(void)IsLocal(service);
},
[&] {
(void)GetLocalAddress(node);
});
}
}