LCOV - code coverage report
Current view: top level - src/test/fuzz - netaddress.cpp (source / functions) Coverage Total Hit
Test: fuzz_coverage.info Lines: 100.0 % 91 91
Test Date: 2024-09-01 05:20:30 Functions: 100.0 % 2 2
Branches: 62.2 % 278 173

             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   [ +  -  +  - ]:        2338 : FUZZ_TARGET(netaddress)
      15                 :             : {
      16                 :        2335 :     FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
      17                 :             : 
      18                 :        2335 :     const CNetAddr net_addr = ConsumeNetAddr(fuzzed_data_provider);
      19         [ +  + ]:        2335 :     (void)net_addr.GetNetClass();
      20   [ +  -  +  + ]:         487 :     if (net_addr.GetNetwork() == Network::NET_IPV4) {
      21   [ +  -  +  - ]:         107 :         assert(net_addr.IsIPv4());
      22                 :         107 :     }
      23   [ +  -  +  + ]:         487 :     if (net_addr.GetNetwork() == Network::NET_IPV6) {
      24   [ +  -  +  - ]:         185 :         assert(net_addr.IsIPv6());
      25                 :         185 :     }
      26   [ +  -  +  + ]:         487 :     if (net_addr.GetNetwork() == Network::NET_ONION) {
      27   [ +  -  +  - ]:          17 :         assert(net_addr.IsTor());
      28                 :          17 :     }
      29   [ +  -  +  + ]:         487 :     if (net_addr.GetNetwork() == Network::NET_I2P) {
      30   [ +  -  +  - ]:          15 :         assert(net_addr.IsI2P());
      31                 :          15 :     }
      32   [ +  -  +  + ]:         487 :     if (net_addr.GetNetwork() == Network::NET_CJDNS) {
      33   [ +  -  +  - ]:          15 :         assert(net_addr.IsCJDNS());
      34                 :          15 :     }
      35   [ +  -  +  + ]:         487 :     if (net_addr.GetNetwork() == Network::NET_INTERNAL) {
      36   [ +  -  +  - ]:          27 :         assert(net_addr.IsInternal());
      37                 :          27 :     }
      38   [ +  -  +  + ]:         487 :     if (net_addr.GetNetwork() == Network::NET_UNROUTABLE) {
      39   [ +  -  +  - ]:         121 :         assert(!net_addr.IsRoutable());
      40                 :         121 :     }
      41         [ +  - ]:         487 :     (void)net_addr.IsBindAny();
      42   [ +  -  +  + ]:         487 :     if (net_addr.IsInternal()) {
      43   [ +  -  +  - ]:          27 :         assert(net_addr.GetNetwork() == Network::NET_INTERNAL);
      44                 :          27 :     }
      45   [ +  -  +  + ]:         487 :     if (net_addr.IsIPv4()) {
      46   [ +  -  +  +  :         153 :         assert(net_addr.GetNetwork() == Network::NET_IPV4 || net_addr.GetNetwork() == Network::NET_UNROUTABLE);
             +  -  +  - ]
      47                 :         153 :     }
      48   [ +  -  +  + ]:         487 :     if (net_addr.IsIPv6()) {
      49   [ +  -  +  +  :         260 :         assert(net_addr.GetNetwork() == Network::NET_IPV6 || net_addr.GetNetwork() == Network::NET_UNROUTABLE);
             +  -  +  - ]
      50                 :         260 :     }
      51         [ +  - ]:         487 :     (void)net_addr.IsLocal();
      52   [ +  -  +  +  :         487 :     if (net_addr.IsRFC1918() || net_addr.IsRFC2544() || net_addr.IsRFC6598() || net_addr.IsRFC5737() || net_addr.IsRFC3927()) {
          +  -  +  +  +  
          -  +  +  +  -  
             +  +  +  - ]
      53   [ +  +  +  - ]:         487 :         assert(net_addr.IsIPv4());
      54                 :          19 :     }
      55         [ +  + ]:          19 :     (void)net_addr.IsRFC2544();
      56   [ +  -  +  +  :         487 :     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()) {
          +  -  +  +  +  
          -  +  +  +  -  
          +  +  +  -  +  
          +  +  -  +  +  
          +  -  +  +  +  
                      - ]
      57   [ +  +  +  - ]:         487 :         assert(net_addr.IsIPv6());
      58                 :          31 :     }
      59         [ +  + ]:          31 :     (void)net_addr.IsRFC3927();
      60         [ +  - ]:         487 :     (void)net_addr.IsRFC3964();
      61   [ +  -  +  + ]:         487 :     if (net_addr.IsRFC4193()) {
      62   [ +  -  +  -  :          44 :         assert(net_addr.GetNetwork() == Network::NET_INTERNAL || net_addr.GetNetwork() == Network::NET_UNROUTABLE);
             +  -  +  - ]
      63                 :          44 :     }
      64         [ +  - ]:         487 :     (void)net_addr.IsRFC4380();
      65         [ +  - ]:         487 :     (void)net_addr.IsRFC4843();
      66         [ +  - ]:         487 :     (void)net_addr.IsRFC4862();
      67         [ +  - ]:         487 :     (void)net_addr.IsRFC5737();
      68         [ +  - ]:         487 :     (void)net_addr.IsRFC6052();
      69         [ +  - ]:         487 :     (void)net_addr.IsRFC6145();
      70         [ +  - ]:         487 :     (void)net_addr.IsRFC6598();
      71         [ +  - ]:         487 :     (void)net_addr.IsRFC7343();
      72   [ +  -  +  + ]:         487 :     if (!net_addr.IsRoutable()) {
      73   [ +  -  +  +  :         148 :         assert(net_addr.GetNetwork() == Network::NET_UNROUTABLE || net_addr.GetNetwork() == Network::NET_INTERNAL);
             +  -  +  - ]
      74                 :         148 :     }
      75   [ +  -  +  + ]:         487 :     if (net_addr.IsTor()) {
      76   [ +  -  +  - ]:          17 :         assert(net_addr.GetNetwork() == Network::NET_ONION);
      77                 :          17 :     }
      78   [ +  -  +  + ]:         487 :     if (net_addr.IsI2P()) {
      79   [ +  -  +  - ]:          15 :         assert(net_addr.GetNetwork() == Network::NET_I2P);
      80                 :          15 :     }
      81   [ +  -  +  + ]:         487 :     if (net_addr.IsCJDNS()) {
      82   [ +  -  +  - ]:          15 :         assert(net_addr.GetNetwork() == Network::NET_CJDNS);
      83                 :          15 :     }
      84         [ +  - ]:         487 :     (void)net_addr.IsValid();
      85         [ +  - ]:         487 :     (void)net_addr.ToStringAddr();
      86                 :             : 
      87   [ +  -  +  - ]:         487 :     const CSubNet sub_net{net_addr, fuzzed_data_provider.ConsumeIntegral<uint8_t>()};
      88         [ +  - ]:         487 :     (void)sub_net.IsValid();
      89         [ +  - ]:         487 :     (void)sub_net.ToString();
      90                 :             : 
      91   [ +  -  +  - ]:         487 :     const CService service{net_addr, fuzzed_data_provider.ConsumeIntegral<uint16_t>()};
      92         [ +  - ]:         487 :     (void)service.GetKey();
      93         [ +  - ]:         487 :     (void)service.GetPort();
      94         [ +  - ]:         487 :     (void)service.ToStringAddrPort();
      95         [ +  - ]:         487 :     (void)CServiceHash()(service);
      96         [ +  - ]:         487 :     (void)CServiceHash(0, 0)(service);
      97                 :             : 
      98                 :         487 :     const CNetAddr other_net_addr = ConsumeNetAddr(fuzzed_data_provider);
      99         [ +  - ]:         487 :     (void)net_addr.GetReachabilityFrom(other_net_addr);
     100         [ +  - ]:         487 :     (void)sub_net.Match(other_net_addr);
     101                 :             : 
     102   [ +  -  +  - ]:         487 :     const CService other_service{net_addr, fuzzed_data_provider.ConsumeIntegral<uint16_t>()};
     103   [ +  -  +  -  :         487 :     assert((service == other_service) != (service != other_service));
                   +  - ]
     104         [ +  - ]:         487 :     (void)(service < other_service);
     105                 :             : 
     106         [ +  - ]:         487 :     const CSubNet sub_net_copy_1{net_addr, other_net_addr};
     107         [ +  - ]:         487 :     const CSubNet sub_net_copy_2{net_addr};
     108                 :             : 
     109         [ +  - ]:         487 :     CNetAddr mutable_net_addr;
     110         [ +  - ]:         487 :     mutable_net_addr.SetIP(net_addr);
     111   [ +  -  +  - ]:         487 :     assert(net_addr == mutable_net_addr);
     112                 :        4183 : }
        

Generated by: LCOV version 2.0-1