LCOV - code coverage report
Current view: top level - src/test/fuzz - netaddress.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 2 80 2.5 %
Date: 2024-01-03 14:57:27 Functions: 1 3 33.3 %
Branches: 2 246 0.8 %

           Branch data     Line data    Source code
       1                 :            : // Copyright (c) 2020-2022 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 <test/fuzz/FuzzedDataProvider.h>
       7                 :            : #include <test/fuzz/fuzz.h>
       8                 :            : #include <test/fuzz/util/net.h>
       9                 :            : 
      10                 :            : #include <cassert>
      11                 :            : #include <cstdint>
      12                 :            : #include <vector>
      13                 :            : 
      14 [ +  - ][ +  - ]:          6 : FUZZ_TARGET(netaddress)
      15                 :            : {
      16                 :          0 :     FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
      17                 :            : 
      18                 :          0 :     const CNetAddr net_addr = ConsumeNetAddr(fuzzed_data_provider);
      19         [ #  # ]:          0 :     (void)net_addr.GetNetClass();
      20 [ #  # ][ #  # ]:          0 :     if (net_addr.GetNetwork() == Network::NET_IPV4) {
      21 [ #  # ][ #  # ]:          0 :         assert(net_addr.IsIPv4());
      22                 :          0 :     }
      23 [ #  # ][ #  # ]:          0 :     if (net_addr.GetNetwork() == Network::NET_IPV6) {
      24 [ #  # ][ #  # ]:          0 :         assert(net_addr.IsIPv6());
      25                 :          0 :     }
      26 [ #  # ][ #  # ]:          0 :     if (net_addr.GetNetwork() == Network::NET_ONION) {
      27 [ #  # ][ #  # ]:          0 :         assert(net_addr.IsTor());
      28                 :          0 :     }
      29 [ #  # ][ #  # ]:          0 :     if (net_addr.GetNetwork() == Network::NET_INTERNAL) {
      30 [ #  # ][ #  # ]:          2 :         assert(net_addr.IsInternal());
      31                 :          0 :     }
      32 [ #  # ][ #  # ]:          0 :     if (net_addr.GetNetwork() == Network::NET_UNROUTABLE) {
      33 [ #  # ][ #  # ]:          0 :         assert(!net_addr.IsRoutable());
      34                 :          0 :     }
      35         [ #  # ]:          0 :     (void)net_addr.IsBindAny();
      36 [ #  # ][ #  # ]:          0 :     if (net_addr.IsInternal()) {
      37 [ #  # ][ #  # ]:          0 :         assert(net_addr.GetNetwork() == Network::NET_INTERNAL);
      38                 :          0 :     }
      39 [ #  # ][ #  # ]:          0 :     if (net_addr.IsIPv4()) {
      40 [ #  # ][ #  # ]:          0 :         assert(net_addr.GetNetwork() == Network::NET_IPV4 || net_addr.GetNetwork() == Network::NET_UNROUTABLE);
         [ #  # ][ #  # ]
      41                 :          0 :     }
      42 [ #  # ][ #  # ]:          0 :     if (net_addr.IsIPv6()) {
      43 [ #  # ][ #  # ]:          0 :         assert(net_addr.GetNetwork() == Network::NET_IPV6 || net_addr.GetNetwork() == Network::NET_UNROUTABLE);
         [ #  # ][ #  # ]
      44                 :          0 :     }
      45         [ #  # ]:          0 :     (void)net_addr.IsLocal();
      46 [ #  # ][ #  # ]:          0 :     if (net_addr.IsRFC1918() || net_addr.IsRFC2544() || net_addr.IsRFC6598() || net_addr.IsRFC5737() || net_addr.IsRFC3927()) {
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      47 [ #  # ][ #  # ]:          0 :         assert(net_addr.IsIPv4());
      48                 :          0 :     }
      49         [ #  # ]:          0 :     (void)net_addr.IsRFC2544();
      50 [ #  # ][ #  # ]:          0 :     if (net_addr.IsRFC3849() || net_addr.IsRFC3964() || net_addr.IsRFC4380() || net_addr.IsRFC4843() || net_addr.IsRFC7343() || net_addr.IsRFC4862() || net_addr.IsRFC6052() || net_addr.IsRFC6145()) {
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
      51 [ #  # ][ #  # ]:          0 :         assert(net_addr.IsIPv6());
      52                 :          0 :     }
      53         [ #  # ]:          0 :     (void)net_addr.IsRFC3927();
      54         [ #  # ]:          0 :     (void)net_addr.IsRFC3964();
      55 [ #  # ][ #  # ]:          0 :     if (net_addr.IsRFC4193()) {
      56 [ #  # ][ #  # ]:          0 :         assert(net_addr.GetNetwork() == Network::NET_INTERNAL || net_addr.GetNetwork() == Network::NET_UNROUTABLE);
         [ #  # ][ #  # ]
      57                 :          0 :     }
      58         [ #  # ]:          0 :     (void)net_addr.IsRFC4380();
      59         [ #  # ]:          0 :     (void)net_addr.IsRFC4843();
      60         [ #  # ]:          0 :     (void)net_addr.IsRFC4862();
      61         [ #  # ]:          0 :     (void)net_addr.IsRFC5737();
      62         [ #  # ]:          0 :     (void)net_addr.IsRFC6052();
      63         [ #  # ]:          0 :     (void)net_addr.IsRFC6145();
      64         [ #  # ]:          0 :     (void)net_addr.IsRFC6598();
      65         [ #  # ]:          0 :     (void)net_addr.IsRFC7343();
      66 [ #  # ][ #  # ]:          0 :     if (!net_addr.IsRoutable()) {
      67 [ #  # ][ #  # ]:          0 :         assert(net_addr.GetNetwork() == Network::NET_UNROUTABLE || net_addr.GetNetwork() == Network::NET_INTERNAL);
         [ #  # ][ #  # ]
      68                 :          0 :     }
      69 [ #  # ][ #  # ]:          0 :     if (net_addr.IsTor()) {
      70 [ #  # ][ #  # ]:          0 :         assert(net_addr.GetNetwork() == Network::NET_ONION);
      71                 :          0 :     }
      72         [ #  # ]:          0 :     (void)net_addr.IsValid();
      73         [ #  # ]:          0 :     (void)net_addr.ToStringAddr();
      74                 :            : 
      75 [ #  # ][ #  # ]:          0 :     const CSubNet sub_net{net_addr, fuzzed_data_provider.ConsumeIntegral<uint8_t>()};
      76         [ #  # ]:          0 :     (void)sub_net.IsValid();
      77         [ #  # ]:          0 :     (void)sub_net.ToString();
      78                 :            : 
      79 [ #  # ][ #  # ]:          0 :     const CService service{net_addr, fuzzed_data_provider.ConsumeIntegral<uint16_t>()};
      80         [ #  # ]:          0 :     (void)service.GetKey();
      81         [ #  # ]:          0 :     (void)service.GetPort();
      82         [ #  # ]:          0 :     (void)service.ToStringAddrPort();
      83         [ #  # ]:          0 :     (void)CServiceHash()(service);
      84         [ #  # ]:          0 :     (void)CServiceHash(0, 0)(service);
      85                 :            : 
      86                 :          0 :     const CNetAddr other_net_addr = ConsumeNetAddr(fuzzed_data_provider);
      87         [ #  # ]:          0 :     (void)net_addr.GetReachabilityFrom(other_net_addr);
      88         [ #  # ]:          0 :     (void)sub_net.Match(other_net_addr);
      89                 :            : 
      90 [ #  # ][ #  # ]:          0 :     const CService other_service{net_addr, fuzzed_data_provider.ConsumeIntegral<uint16_t>()};
      91 [ #  # ][ #  # ]:          0 :     assert((service == other_service) != (service != other_service));
                 [ #  # ]
      92         [ #  # ]:          0 :     (void)(service < other_service);
      93                 :            : 
      94         [ #  # ]:          0 :     const CSubNet sub_net_copy_1{net_addr, other_net_addr};
      95         [ #  # ]:          0 :     const CSubNet sub_net_copy_2{net_addr};
      96                 :            : 
      97         [ #  # ]:          0 :     CNetAddr mutable_net_addr;
      98         [ #  # ]:          0 :     mutable_net_addr.SetIP(net_addr);
      99 [ #  # ][ #  # ]:          0 :     assert(net_addr == mutable_net_addr);
     100                 :          0 : }

Generated by: LCOV version 1.14