LCOV - code coverage report
Current view: top level - src/test/fuzz - netaddress.cpp (source / functions) Coverage Total Hit
Test: test_bitcoin_coverage.info Lines: 0.0 % 74 0
Test Date: 2024-08-28 04:44:32 Functions: 0.0 % 2 0
Branches: 0.0 % 246 0

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

Generated by: LCOV version 2.0-1