18 const std::string
name = fuzzed_data_provider.ConsumeRandomLengthString(512);
19 const unsigned int max_results = fuzzed_data_provider.ConsumeIntegral<
unsigned int>();
20 const bool allow_lookup = fuzzed_data_provider.ConsumeBool();
21 const uint16_t default_port = fuzzed_data_provider.ConsumeIntegral<uint16_t>();
23 auto fuzzed_dns_lookup_function = [&](
const std::string&, bool) {
24 std::vector<CNetAddr> resolved_addresses;
26 resolved_addresses.push_back(
ConsumeNetAddr(fuzzed_data_provider));
28 return resolved_addresses;
32 const std::vector<CNetAddr> resolved_addresses{
LookupHost(
name, max_results, allow_lookup, fuzzed_dns_lookup_function)};
33 for (
const CNetAddr& resolved_address : resolved_addresses) {
34 assert(!resolved_address.IsInternal());
36 assert(resolved_addresses.size() <= max_results || max_results == 0);
39 const std::optional<CNetAddr> resolved_address{
LookupHost(
name, allow_lookup, fuzzed_dns_lookup_function)};
40 if (resolved_address.has_value()) {
41 assert(!resolved_address.value().IsInternal());
45 const std::vector<CService> resolved_services{
Lookup(
name, default_port, allow_lookup, max_results, fuzzed_dns_lookup_function)};
46 for (
const CNetAddr& resolved_service : resolved_services) {
47 assert(!resolved_service.IsInternal());
49 assert(resolved_services.size() <= max_results || max_results == 0);
52 const std::optional<CService> resolved_service{
Lookup(
name, default_port, allow_lookup, fuzzed_dns_lookup_function)};
53 if (resolved_service.has_value()) {
54 assert(!resolved_service.value().IsInternal());
A combination of a network address (CNetAddr) and a (TCP) port.
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
CSubNet LookupSubNet(const std::string &subnet_str)
Parse and resolve a specified subnet string into the appropriate internal representation.
std::vector< CNetAddr > LookupHost(const std::string &name, unsigned int nMaxSolutions, bool fAllowLookup, DNSLookupFn dns_lookup_function)
Resolve a host string to its corresponding network addresses.
std::vector< CService > Lookup(const std::string &name, uint16_t portDefault, bool fAllowLookup, unsigned int nMaxSolutions, DNSLookupFn dns_lookup_function)
Resolve a service string to its corresponding service.
CService LookupNumeric(const std::string &name, uint16_t portDefault, DNSLookupFn dns_lookup_function)
Resolve a service string with a numeric IP to its first corresponding service.
FUZZ_TARGET(netbase_dns_lookup)
CNetAddr ConsumeNetAddr(FuzzedDataProvider &fuzzed_data_provider, FastRandomContext *rand) noexcept
Create a CNetAddr.