Coverage Report

Created: 2026-08-25 19:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/bitcoin/src/test/fuzz/netbase_dns_lookup.cpp
Line
Count
Source
1
// Copyright (c) 2021-present The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#include <netaddress.h>
6
#include <netbase.h>
7
#include <test/fuzz/FuzzedDataProvider.h>
8
#include <test/fuzz/fuzz.h>
9
#include <test/fuzz/util/net.h>
10
11
#include <cstdint>
12
#include <string>
13
#include <vector>
14
15
FUZZ_TARGET(netbase_dns_lookup)
16
767
{
17
767
    FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
18
767
    const std::string name = fuzzed_data_provider.ConsumeRandomLengthString(512);
19
767
    const unsigned int max_results = fuzzed_data_provider.ConsumeIntegral<unsigned int>();
20
767
    const bool allow_lookup = fuzzed_data_provider.ConsumeBool();
21
767
    const uint16_t default_port = fuzzed_data_provider.ConsumeIntegral<uint16_t>();
22
23
3.72k
    auto fuzzed_dns_lookup_function = [&](const std::string&, bool) {
24
3.72k
        std::vector<CNetAddr> resolved_addresses;
25
1.14M
        LIMITED_WHILE (fuzzed_data_provider.ConsumeBool(), 10000) {
26
1.14M
            resolved_addresses.push_back(ConsumeNetAddr(fuzzed_data_provider));
27
1.14M
        }
28
3.72k
        return resolved_addresses;
29
3.72k
    };
30
31
767
    {
32
767
        const std::vector<CNetAddr> resolved_addresses{LookupHost(name, max_results, allow_lookup, fuzzed_dns_lookup_function)};
33
340k
        for (const CNetAddr& resolved_address : resolved_addresses) {
  Branch (33:47): [True: 340k, False: 767]
34
340k
            assert(!resolved_address.IsInternal());
  Branch (34:13): [True: 340k, False: 0]
35
340k
        }
36
767
        assert(resolved_addresses.size() <= max_results || max_results == 0);
  Branch (36:9): [True: 728, False: 39]
  Branch (36:9): [True: 39, False: 0]
  Branch (36:9): [True: 767, False: 0]
37
767
    }
38
767
    {
39
767
        const std::optional<CNetAddr> resolved_address{LookupHost(name, allow_lookup, fuzzed_dns_lookup_function)};
40
767
        if (resolved_address.has_value()) {
  Branch (40:13): [True: 267, False: 500]
41
267
            assert(!resolved_address.value().IsInternal());
  Branch (41:13): [True: 267, False: 0]
42
267
        }
43
767
    }
44
767
    {
45
767
        const std::vector<CService> resolved_services{Lookup(name, default_port, allow_lookup, max_results, fuzzed_dns_lookup_function)};
46
277k
        for (const CNetAddr& resolved_service : resolved_services) {
  Branch (46:47): [True: 277k, False: 767]
47
277k
            assert(!resolved_service.IsInternal());
  Branch (47:13): [True: 277k, False: 0]
48
277k
        }
49
767
        assert(resolved_services.size() <= max_results || max_results == 0);
  Branch (49:9): [True: 733, False: 34]
  Branch (49:9): [True: 34, False: 0]
  Branch (49:9): [True: 767, False: 0]
50
767
    }
51
767
    {
52
767
        const std::optional<CService> resolved_service{Lookup(name, default_port, allow_lookup, fuzzed_dns_lookup_function)};
53
767
        if (resolved_service.has_value()) {
  Branch (53:13): [True: 247, False: 520]
54
247
            assert(!resolved_service.value().IsInternal());
  Branch (54:13): [True: 247, False: 0]
55
247
        }
56
767
    }
57
767
    {
58
767
        CService resolved_service = LookupNumeric(name, default_port, fuzzed_dns_lookup_function);
59
767
        assert(!resolved_service.IsInternal());
  Branch (59:9): [True: 767, False: 0]
60
767
    }
61
767
    {
62
767
        (void)LookupSubNet(name);
63
767
    }
64
767
}