Skip to content

Commit 0a1cf6c

Browse files
author
MarcoFalke
committed
Merge #20908: fuzz: Use mocktime in process_message* fuzz targets
fa0a864 fuzz: Use mocktime in process_message* fuzz targets (MarcoFalke) Pull request description: Use mocktime to allow time to advance deterministically during execution of a fuzz input. This also allows to drop the call to `JumpOutOfIbd`. ACKs for top commit: practicalswift: cr ACK fa0a864 Tree-SHA512: e92fc70ec6bd49760173cb202549f364304e22b3f7127b9a4da8447cf9341008e477ad42c2599c2fde167bbcbc0e2d139709b4ef6371788bc2c1c3b7f589e11d
2 parents f91587f + fa0a864 commit 0a1cf6c

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/test/fuzz/process_message.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,25 @@ void initialize_process_message()
5555
void fuzz_target(const std::vector<uint8_t>& buffer, const std::string& LIMIT_TO_MESSAGE_TYPE)
5656
{
5757
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
58+
5859
ConnmanTestMsg& connman = *(ConnmanTestMsg*)g_setup->m_node.connman.get();
5960
TestChainState& chainstate = *(TestChainState*)&g_setup->m_node.chainman->ActiveChainstate();
61+
SetMockTime(1610000000); // any time to successfully reset ibd
6062
chainstate.ResetIbd();
63+
6164
const std::string random_message_type{fuzzed_data_provider.ConsumeBytesAsString(CMessageHeader::COMMAND_SIZE).c_str()};
6265
if (!LIMIT_TO_MESSAGE_TYPE.empty() && random_message_type != LIMIT_TO_MESSAGE_TYPE) {
6366
return;
6467
}
65-
const bool jump_out_of_ibd{fuzzed_data_provider.ConsumeBool()};
66-
if (jump_out_of_ibd) chainstate.JumpOutOfIbd();
6768
CNode& p2p_node = *ConsumeNodeAsUniquePtr(fuzzed_data_provider).release();
6869
FillNode(fuzzed_data_provider, p2p_node);
6970
p2p_node.fSuccessfullyConnected = true;
7071
connman.AddTestNode(p2p_node);
7172
g_setup->m_node.peerman->InitializeNode(&p2p_node);
7273

74+
const auto mock_time = ConsumeTime(fuzzed_data_provider);
75+
SetMockTime(mock_time);
76+
7377
// fuzzed_data_provider is fully consumed after this call, don't use it
7478
CDataStream random_bytes_data_stream{fuzzed_data_provider.ConsumeRemainingBytes<unsigned char>(), SER_NETWORK, PROTOCOL_VERSION};
7579
try {

src/test/fuzz/process_messages.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ FUZZ_TARGET_INIT(process_messages, initialize_process_messages)
4141

4242
ConnmanTestMsg& connman = *(ConnmanTestMsg*)g_setup->m_node.connman.get();
4343
TestChainState& chainstate = *(TestChainState*)&g_setup->m_node.chainman->ActiveChainstate();
44+
SetMockTime(1610000000); // any time to successfully reset ibd
4445
chainstate.ResetIbd();
45-
std::vector<CNode*> peers;
46-
bool jump_out_of_ibd{false};
4746

47+
std::vector<CNode*> peers;
4848
const auto num_peers_to_add = fuzzed_data_provider.ConsumeIntegralInRange(1, 3);
4949
for (int i = 0; i < num_peers_to_add; ++i) {
5050
peers.push_back(ConsumeNodeAsUniquePtr(fuzzed_data_provider, i).release());
@@ -59,10 +59,11 @@ FUZZ_TARGET_INIT(process_messages, initialize_process_messages)
5959
}
6060

6161
while (fuzzed_data_provider.ConsumeBool()) {
62-
if (!jump_out_of_ibd) jump_out_of_ibd = fuzzed_data_provider.ConsumeBool();
63-
if (jump_out_of_ibd && chainstate.IsInitialBlockDownload()) chainstate.JumpOutOfIbd();
6462
const std::string random_message_type{fuzzed_data_provider.ConsumeBytesAsString(CMessageHeader::COMMAND_SIZE).c_str()};
6563

64+
const auto mock_time = ConsumeTime(fuzzed_data_provider);
65+
SetMockTime(mock_time);
66+
6667
CSerializedNetMsg net_msg;
6768
net_msg.m_type = random_message_type;
6869
net_msg.data = ConsumeRandomLengthByteVector(fuzzed_data_provider);

0 commit comments

Comments
 (0)