| 32 | } |
| 33 | |
| 34 | FUZZ_TARGET_INIT(process_messages, initialize_process_messages) |
| 35 | { |
| 36 | FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size()); |
| 37 | |
| 38 | ConnmanTestMsg& connman = *static_cast<ConnmanTestMsg*>(g_setup->m_node.connman.get()); |
| 39 | TestChainState& chainstate = *static_cast<TestChainState*>(&g_setup->m_node.chainman->ActiveChainstate()); |
| 40 | SetMockTime(1610000000); // any time to successfully reset ibd |
| 41 | chainstate.ResetIbd(); |
| 42 | |
| 43 | std::vector<CNode*> peers; |
| 44 | const auto num_peers_to_add = fuzzed_data_provider.ConsumeIntegralInRange(1, 3); |
| 45 | for (int i = 0; i < num_peers_to_add; ++i) { |
| 46 | peers.push_back(ConsumeNodeAsUniquePtr(fuzzed_data_provider, i).release()); |
| 47 | CNode& p2p_node = *peers.back(); |
| 48 | |
| 49 | g_setup->m_node.peerman->InitializeNode(&p2p_node); |
| 50 | FillNode(fuzzed_data_provider, connman, *g_setup->m_node.peerman, p2p_node); |
| 51 | |
| 52 | connman.AddTestNode(p2p_node); |
| 53 | } |
| 54 | |
| 55 | LIMITED_WHILE(fuzzed_data_provider.ConsumeBool(), 100) { |
| 56 | // ELEMENTS: this loop runs on a single core and achieves nothing that couldn't |
| 57 | // be achieved by just repeating the fuzz runs. It typically takes around 11 |
| 58 | // minutes on Bitcoin and around 60 minutes on Elements (presumably because the |
| 59 | // seed vectors aren't valid Elements messages so the fuzzer gets lost and starts |
| 60 | // adding tons of iterations). |
| 61 | // |
| 62 | // Capping to 100 iterations reduces the run time to 4-5 minutes on both Bitcoin |
| 63 | // and Elements. |
| 64 | |
| 65 | const std::string random_message_type{fuzzed_data_provider.ConsumeBytesAsString(CMessageHeader::COMMAND_SIZE).c_str()}; |
| 66 | |
| 67 | const auto mock_time = ConsumeTime(fuzzed_data_provider); |
| 68 | SetMockTime(mock_time); |
| 69 | |
| 70 | CSerializedNetMsg net_msg; |
| 71 | net_msg.m_type = random_message_type; |
| 72 | net_msg.data = ConsumeRandomLengthByteVector(fuzzed_data_provider); |
| 73 | |
| 74 | CNode& random_node = *PickValue(fuzzed_data_provider, peers); |
| 75 | |
| 76 | (void)connman.ReceiveMsgFrom(random_node, net_msg); |
| 77 | random_node.fPauseSend = false; |
| 78 | |
| 79 | try { |
| 80 | connman.ProcessMessagesOnce(random_node); |
| 81 | } catch (const std::ios_base::failure&) { |
| 82 | } |
| 83 | { |
| 84 | LOCK(random_node.cs_sendProcessing); |
| 85 | g_setup->m_node.peerman->SendMessages(&random_node); |
| 86 | } |
| 87 | } |
| 88 | SyncWithValidationInterfaceQueue(); |
| 89 | g_setup->m_node.connman->StopNodes(); |
| 90 | } |
nothing calls this directly
no test coverage detected