diff options
Diffstat (limited to 'src/test/fuzz/netbase_dns_lookup.cpp')
-rw-r--r-- | src/test/fuzz/netbase_dns_lookup.cpp | 24 |
1 files changed, 9 insertions, 15 deletions
diff --git a/src/test/fuzz/netbase_dns_lookup.cpp b/src/test/fuzz/netbase_dns_lookup.cpp index 786440c8a4..7be8b13743 100644 --- a/src/test/fuzz/netbase_dns_lookup.cpp +++ b/src/test/fuzz/netbase_dns_lookup.cpp @@ -12,27 +12,22 @@ #include <string> #include <vector> -namespace { -FuzzedDataProvider* fuzzed_data_provider_ptr = nullptr; - -std::vector<CNetAddr> fuzzed_dns_lookup_function(const std::string& name, bool allow_lookup) -{ - std::vector<CNetAddr> resolved_addresses; - while (fuzzed_data_provider_ptr->ConsumeBool()) { - resolved_addresses.push_back(ConsumeNetAddr(*fuzzed_data_provider_ptr)); - } - return resolved_addresses; -} -} // namespace - FUZZ_TARGET(netbase_dns_lookup) { FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()}; - fuzzed_data_provider_ptr = &fuzzed_data_provider; const std::string name = fuzzed_data_provider.ConsumeRandomLengthString(512); const unsigned int max_results = fuzzed_data_provider.ConsumeIntegral<unsigned int>(); const bool allow_lookup = fuzzed_data_provider.ConsumeBool(); const int default_port = fuzzed_data_provider.ConsumeIntegral<int>(); + + auto fuzzed_dns_lookup_function = [&](const std::string&, bool) { + std::vector<CNetAddr> resolved_addresses; + while (fuzzed_data_provider.ConsumeBool()) { + resolved_addresses.push_back(ConsumeNetAddr(fuzzed_data_provider)); + } + return resolved_addresses; + }; + { std::vector<CNetAddr> resolved_addresses; if (LookupHost(name, resolved_addresses, max_results, allow_lookup, fuzzed_dns_lookup_function)) { @@ -73,5 +68,4 @@ FUZZ_TARGET(netbase_dns_lookup) assert(resolved_subnet.IsValid()); } } - fuzzed_data_provider_ptr = nullptr; } |