fuzz: connman, `m_nodes` is always empty #27980

issue brunoerg opened this issue on June 26, 2023
  1. brunoerg commented at 7:52 PM on June 26, 2023: contributor

    m_nodes in CConnman is always empty in connman target (since we don't call CreateNodeFromAcceptedSocket/OpenNetworkConnection for an obvious reason). Because of this, the calls for DisconnectNode, FindNode, ForEachNode, GetNodeStats and many other ones seems to be "useless". That's the reason we're not getting coverage (at all) for many of these covered functions (See: https://marcofalke.github.io/b-c-cov/fuzz.coverage/src/net.cpp.gcov.html).

    I suppose we could use ConnmanTestMsg here and then we can use AddTestNode, not sure whether it's the best approach:

    diff --git a/src/test/fuzz/connman.cpp b/src/test/fuzz/connma
    n.cpp
    index f81658b83..607a91488 100644
    --- a/src/test/fuzz/connman.cpp
    +++ b/src/test/fuzz/connman.cpp
    @@ -32,7 +32,7 @@ FUZZ_TARGET_INIT(connman, initialize_connman)
     {
         FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
         SetMockTime(ConsumeTime(fuzzed_data_provider));
    -    CConnman connman{fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
    +    ConnmanTestMsg connman{fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
                          fuzzed_data_provider.ConsumeIntegral<uint64_t>(),
                          *g_setup->m_node.addrman,
                          *g_setup->m_node.netgroupman,
    @@ -41,6 +41,15 @@ FUZZ_TARGET_INIT(connman, initialize_connman)
         CNode random_node = ConsumeNode(fuzzed_data_provider);
         CSubNet random_subnet;
         std::string random_string;
    +
    +    {
    +        LOCK(NetEventsInterface::g_msgproc_mutex);
    +        for (int i = 0; i < 100; i++) {
    +            CNode& p2p_node = *ConsumeNodeAsUniquePtr(fuzzed_data_provider).release();
    +            connman.AddTestNode(p2p_node);
    +        }
    +    }
    +
         LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 10000) {
             CallOneOf(
                 fuzzed_data_provider,
    @@ -128,4 +137,6 @@ FUZZ_TARGET_INIT(connman, initialize_connman)
         (void)connman.GetTotalBytesSent();
         (void)connman.GetTryNewOutboundPeer();
         (void)connman.GetUseAddrmanOutgoing();
    +
    +    connman.ClearTestNodes();
     }
    
  2. brunoerg commented at 1:16 PM on July 15, 2023: contributor
  3. maflcko commented at 7:56 AM on July 16, 2023: member

    Jup. Sgtm. If there are no downsides, I don't see a reason not to do it.

  4. fanquake closed this on Jul 31, 2023

  5. sidhujag referenced this in commit b428e3c7cd on Aug 9, 2023
  6. BlackcoinDev referenced this in commit 44b05bf3fe on Feb 5, 2024
  7. bitcoin locked this on Jul 30, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-02 06:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me