From fe624631aeb4b5fbad732ad6476c5cd986674b4f Mon Sep 17 00:00:00 2001 From: brunoerg Date: Wed, 28 Feb 2024 12:49:44 -0300 Subject: [PATCH] fuzz: fuzz `connman` with a non-empty addrman --- src/test/fuzz/connman.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/test/fuzz/connman.cpp b/src/test/fuzz/connman.cpp index beefc9d82ed..a3914bfcf31 100644 --- a/src/test/fuzz/connman.cpp +++ b/src/test/fuzz/connman.cpp @@ -20,6 +20,12 @@ namespace { const TestingSetup* g_setup; + +int32_t GetCheckRatio() +{ + return std::clamp(g_setup->m_node.args->GetIntArg("-checkaddrman", 0), 0, 1000000); +} + } // namespace void initialize_connman() @@ -32,9 +38,21 @@ FUZZ_TARGET(connman, .init = initialize_connman) { FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()}; SetMockTime(ConsumeTime(fuzzed_data_provider)); + auto netgroupman{*g_setup->m_node.netgroupman}; + auto addr_man_ptr{std::make_unique(netgroupman, fuzzed_data_provider, GetCheckRatio())}; + if (fuzzed_data_provider.ConsumeBool()) { + const std::vector serialized_data{ConsumeRandomLengthByteVector(fuzzed_data_provider)}; + DataStream ds{serialized_data}; + try { + ds >> *addr_man_ptr; + } catch (const std::ios_base::failure&) { + addr_man_ptr = std::make_unique(netgroupman, fuzzed_data_provider, GetCheckRatio()); + } + } + AddrManDeterministic& addr_man{*addr_man_ptr}; ConnmanTestMsg connman{fuzzed_data_provider.ConsumeIntegral(), fuzzed_data_provider.ConsumeIntegral(), - *g_setup->m_node.addrman, + addr_man, *g_setup->m_node.netgroupman, Params(), fuzzed_data_provider.ConsumeBool()};