diff options
author | MarcoFalke <falke.marco@gmail.com> | 2021-03-15 17:26:13 +0100 |
---|---|---|
committer | MarcoFalke <falke.marco@gmail.com> | 2021-03-15 17:26:16 +0100 |
commit | 9a5e097435a3172bb5f31b8f1e4948a7c69df5c9 (patch) | |
tree | cd724e164587ac209f471bfe4def24bd6d048ed3 | |
parent | eceb3f7707d6793152a00476adae1c4e268ce6f3 (diff) | |
parent | 7c8c140ecc95ab2ac90e20951416886c9ac5fa93 (diff) | |
download | bitcoin-9a5e097435a3172bb5f31b8f1e4948a7c69df5c9.tar.xz |
Merge #21443: fuzz: Implement fuzzed_dns_lookup_function as a lambda
7c8c140ecc95ab2ac90e20951416886c9ac5fa93 fuzz: Implement fuzzed_dns_lookup_function as lambda (practicalswift)
Pull request description:
Implement `fuzzed_dns_lookup_function` as a lambda.
As wisely suggested by MarcoFalke in https://github.com/bitcoin/bitcoin/pull/19415#discussion_r594244506. Thanks! :)
ACKs for top commit:
MarcoFalke:
cr ACK 7c8c140ecc95ab2ac90e20951416886c9ac5fa93
vasild:
ACK 7c8c140ecc95ab2ac90e20951416886c9ac5fa93
Tree-SHA512: b175f2ad42e9a2be1f769ac677b2872e73ae621731d27e9a24bedadc14d9a6682c7fd1946a0df436d37e7b0cc0d212c1eef69f0409fb975cf9c460cd45f6e4ac
-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; } |