LCOV - code coverage report
Current view: top level - src/test/fuzz - net.cpp (source / functions) Hit Total Coverage
Test: fuzz_coverage.info Lines: 3 51 5.9 %
Date: 2023-11-10 23:46:46 Functions: 1 13 7.7 %
Branches: 3 56 5.4 %

           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 <chainparams.h>
       6                 :            : #include <net.h>
       7                 :            : #include <net_permissions.h>
       8                 :            : #include <netaddress.h>
       9                 :            : #include <protocol.h>
      10                 :            : #include <random.h>
      11                 :            : #include <test/fuzz/FuzzedDataProvider.h>
      12                 :            : #include <test/fuzz/fuzz.h>
      13                 :            : #include <test/fuzz/util.h>
      14                 :            : #include <test/fuzz/util/net.h>
      15                 :            : #include <test/util/net.h>
      16                 :            : #include <test/util/setup_common.h>
      17         [ +  - ]:          2 : #include <util/asmap.h>
      18         [ +  - ]:          2 : #include <util/chaintype.h>
      19                 :            : 
      20                 :            : #include <cstdint>
      21                 :            : #include <optional>
      22                 :            : #include <string>
      23                 :            : #include <vector>
      24                 :            : 
      25                 :          0 : void initialize_net()
      26                 :            : {
      27 [ #  # ][ #  # ]:          0 :     static const auto testing_setup = MakeNoLogFileContext<>(ChainType::MAIN);
                 [ #  # ]
      28                 :          0 : }
      29                 :            : 
      30         [ +  - ]:          4 : FUZZ_TARGET(net, .init = initialize_net)
      31                 :            : {
      32                 :          0 :     FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
      33                 :          0 :     SetMockTime(ConsumeTime(fuzzed_data_provider));
      34                 :          0 :     CNode node{ConsumeNode(fuzzed_data_provider)};
      35 [ #  # ][ #  # ]:          0 :     node.SetCommonVersion(fuzzed_data_provider.ConsumeIntegral<int>());
      36 [ #  # ][ #  # ]:          0 :     LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
                 [ #  # ]
      37         [ #  # ]:          0 :         CallOneOf(
      38                 :            :             fuzzed_data_provider,
      39                 :          0 :             [&] {
      40                 :          0 :                 node.CloseSocketDisconnect();
      41                 :          0 :             },
      42                 :          0 :             [&] {
      43                 :          0 :                 CNodeStats stats;
      44         [ #  # ]:          0 :                 node.CopyStats(stats);
      45                 :          0 :             },
      46                 :          0 :             [&] {
      47                 :          0 :                 const CNode* add_ref_node = node.AddRef();
      48         [ #  # ]:          0 :                 assert(add_ref_node == &node);
      49                 :          0 :             },
      50                 :          0 :             [&] {
      51         [ #  # ]:          0 :                 if (node.GetRefCount() > 0) {
      52                 :          0 :                     node.Release();
      53                 :          0 :                 }
      54                 :          0 :             },
      55                 :          0 :             [&] {
      56                 :          0 :                 const std::optional<CService> service_opt = ConsumeDeserializable<CService>(fuzzed_data_provider, ConsumeDeserializationParams<CNetAddr::SerParams>(fuzzed_data_provider));
      57         [ #  # ]:          0 :                 if (!service_opt) {
      58                 :          0 :                     return;
      59                 :            :                 }
      60         [ #  # ]:          0 :                 node.SetAddrLocal(*service_opt);
      61         [ #  # ]:          0 :             },
      62                 :          0 :             [&] {
      63                 :          0 :                 const std::vector<uint8_t> b = ConsumeRandomLengthByteVector(fuzzed_data_provider);
      64                 :            :                 bool complete;
      65 [ #  # ][ #  # ]:          0 :                 node.ReceiveMsgBytes(b, complete);
      66                 :          0 :             });
      67                 :          0 :     }
      68                 :            : 
      69         [ #  # ]:          0 :     (void)node.GetAddrLocal();
      70         [ #  # ]:          0 :     (void)node.GetId();
      71         [ #  # ]:          0 :     (void)node.GetLocalNonce();
      72         [ #  # ]:          0 :     const int ref_count = node.GetRefCount();
      73         [ #  # ]:          0 :     assert(ref_count >= 0);
      74         [ #  # ]:          0 :     (void)node.GetCommonVersion();
      75                 :            : 
      76                 :          0 :     const NetPermissionFlags net_permission_flags = ConsumeWeakEnum(fuzzed_data_provider, ALL_NET_PERMISSION_FLAGS);
      77         [ #  # ]:          0 :     (void)node.HasPermission(net_permission_flags);
      78         [ #  # ]:          0 :     (void)node.ConnectedThroughNetwork();
      79                 :          0 : }

Generated by: LCOV version 1.14