Skip to content

Commit 0f55294

Browse files
author
MarcoFalke
committed
Merge #18875: fuzz: Stop nodes in process_message* fuzzers
fab860a fuzz: Stop nodes in process_message* fuzzers (MarcoFalke) 6666c82 fuzz: Give CNode ownership to ConnmanTestMsg in process_message fuzz harness (MarcoFalke) Pull request description: Background is that I saw an integer overflow in net_processing ``` #30629113 REDUCE cov: 25793 ft: 142917 corp: 3421/2417Kb lim: 4096 exec/s: 89 rss: 614Mb L: 1719/4096 MS: 1 EraseBytes- net_processing.cpp:977:25: runtime error: signed integer overflow: 2147483624 + 100 cannot be represented in type 'int' SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior net_processing.cpp:977:25 in net_processing.cpp:985:9: runtime error: signed integer overflow: -2147483572 - 100 cannot be represented in type 'int' SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior net_processing.cpp:985:9 in ``` Telling from the line numbers, it looks like `nMisbehavior` wrapped around. Fix that by calling `StopNodes` after each exec, which should clear the node state and thus `nMisbehavior`. ACKs for top commit: practicalswift: ACK fab860a Tree-SHA512: 891c081d5843565d891aec028b6c27ef3fa39bc40ae78238e81d8f784b4d4b49cb870998574725a5159dd03aeeb2e0b9bc3d3bb51d57d1231ef42e3394b2d639
2 parents 4206551 + fab860a commit 0f55294

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/test/fuzz/process_message.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <test/fuzz/FuzzedDataProvider.h>
1515
#include <test/fuzz/fuzz.h>
1616
#include <test/util/mining.h>
17+
#include <test/util/net.h>
1718
#include <test/util/setup_common.h>
1819
#include <util/memory.h>
1920
#include <validationinterface.h>
@@ -63,19 +64,23 @@ void initialize()
6364
void test_one_input(const std::vector<uint8_t>& buffer)
6465
{
6566
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
67+
ConnmanTestMsg& connman = *(ConnmanTestMsg*)g_setup->m_node.connman.get();
6668
const std::string random_message_type{fuzzed_data_provider.ConsumeBytesAsString(CMessageHeader::COMMAND_SIZE).c_str()};
6769
if (!LIMIT_TO_MESSAGE_TYPE.empty() && random_message_type != LIMIT_TO_MESSAGE_TYPE) {
6870
return;
6971
}
7072
CDataStream random_bytes_data_stream{fuzzed_data_provider.ConsumeRemainingBytes<unsigned char>(), SER_NETWORK, PROTOCOL_VERSION};
71-
CNode p2p_node{0, ServiceFlags(NODE_NETWORK | NODE_WITNESS | NODE_BLOOM), 0, INVALID_SOCKET, CAddress{CService{in_addr{0x0100007f}, 7777}, NODE_NETWORK}, 0, 0, CAddress{}, std::string{}, false};
73+
CNode& p2p_node = *MakeUnique<CNode>(0, ServiceFlags(NODE_NETWORK | NODE_WITNESS | NODE_BLOOM), 0, INVALID_SOCKET, CAddress{CService{in_addr{0x0100007f}, 7777}, NODE_NETWORK}, 0, 0, CAddress{}, std::string{}, false).release();
7274
p2p_node.fSuccessfullyConnected = true;
7375
p2p_node.nVersion = PROTOCOL_VERSION;
7476
p2p_node.SetSendVersion(PROTOCOL_VERSION);
77+
connman.AddTestNode(p2p_node);
7578
g_setup->m_node.peer_logic->InitializeNode(&p2p_node);
7679
try {
7780
(void)ProcessMessage(&p2p_node, random_message_type, random_bytes_data_stream, GetTimeMillis(), Params(), *g_setup->m_node.chainman, *g_setup->m_node.mempool, g_setup->m_node.connman.get(), g_setup->m_node.banman.get(), std::atomic<bool>{false});
7881
} catch (const std::ios_base::failure&) {
7982
}
8083
SyncWithValidationInterfaceQueue();
84+
LOCK2(::cs_main, g_cs_orphans); // See init.cpp for rationale for implicit locking order requirement
85+
g_setup->m_node.connman->StopNodes();
8186
}

src/test/fuzz/process_messages.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ void test_one_input(const std::vector<uint8_t>& buffer)
7575
} catch (const std::ios_base::failure&) {
7676
}
7777
}
78-
connman.ClearTestNodes();
7978
SyncWithValidationInterfaceQueue();
79+
LOCK2(::cs_main, g_cs_orphans); // See init.cpp for rationale for implicit locking order requirement
80+
g_setup->m_node.connman->StopNodes();
8081
}

0 commit comments

Comments
 (0)