diff options
author | practicalswift <practicalswift@users.noreply.github.com> | 2021-03-15 15:20:03 +0000 |
---|---|---|
committer | practicalswift <practicalswift@users.noreply.github.com> | 2021-03-15 15:27:25 +0000 |
commit | 7c8c140ecc95ab2ac90e20951416886c9ac5fa93 (patch) | |
tree | cd724e164587ac209f471bfe4def24bd6d048ed3 /src/test | |
parent | eceb3f7707d6793152a00476adae1c4e268ce6f3 (diff) | |
download | bitcoin-7c8c140ecc95ab2ac90e20951416886c9ac5fa93.tar.xz |
fuzz: Implement fuzzed_dns_lookup_function as lambda
Diffstat (limited to 'src/test')
-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; } |