mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
merge bitcoin#20908: Use mocktime in process_message* fuzz targets
This commit is contained in:
parent
1ecd587183
commit
d4d6b32934
@ -74,15 +74,16 @@ void initialize_process_message()
|
|||||||
void fuzz_target(FuzzBufferType buffer, const std::string& LIMIT_TO_MESSAGE_TYPE)
|
void fuzz_target(FuzzBufferType buffer, const std::string& LIMIT_TO_MESSAGE_TYPE)
|
||||||
{
|
{
|
||||||
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
FuzzedDataProvider fuzzed_data_provider(buffer.data(), buffer.size());
|
||||||
|
|
||||||
ConnmanTestMsg& connman = *(ConnmanTestMsg*)g_setup->m_node.connman.get();
|
ConnmanTestMsg& connman = *(ConnmanTestMsg*)g_setup->m_node.connman.get();
|
||||||
TestChainState& chainstate = *(TestChainState*)&g_setup->m_node.chainman->ActiveChainstate();
|
TestChainState& chainstate = *(TestChainState*)&g_setup->m_node.chainman->ActiveChainstate();
|
||||||
|
SetMockTime(1610000000); // any time to successfully reset ibd
|
||||||
chainstate.ResetIbd();
|
chainstate.ResetIbd();
|
||||||
|
|
||||||
const std::string random_message_type{fuzzed_data_provider.ConsumeBytesAsString(CMessageHeader::COMMAND_SIZE).c_str()};
|
const std::string random_message_type{fuzzed_data_provider.ConsumeBytesAsString(CMessageHeader::COMMAND_SIZE).c_str()};
|
||||||
if (!LIMIT_TO_MESSAGE_TYPE.empty() && random_message_type != LIMIT_TO_MESSAGE_TYPE) {
|
if (!LIMIT_TO_MESSAGE_TYPE.empty() && random_message_type != LIMIT_TO_MESSAGE_TYPE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const bool jump_out_of_ibd{fuzzed_data_provider.ConsumeBool()};
|
|
||||||
if (jump_out_of_ibd) chainstate.JumpOutOfIbd();
|
|
||||||
CNode& p2p_node = *ConsumeNodeAsUniquePtr(fuzzed_data_provider).release();
|
CNode& p2p_node = *ConsumeNodeAsUniquePtr(fuzzed_data_provider).release();
|
||||||
|
|
||||||
const bool successfully_connected{fuzzed_data_provider.ConsumeBool()};
|
const bool successfully_connected{fuzzed_data_provider.ConsumeBool()};
|
||||||
@ -91,6 +92,9 @@ void fuzz_target(FuzzBufferType buffer, const std::string& LIMIT_TO_MESSAGE_TYPE
|
|||||||
g_setup->m_node.peerman->InitializeNode(&p2p_node);
|
g_setup->m_node.peerman->InitializeNode(&p2p_node);
|
||||||
FillNode(fuzzed_data_provider, p2p_node, /* init_version */ successfully_connected);
|
FillNode(fuzzed_data_provider, p2p_node, /* init_version */ successfully_connected);
|
||||||
|
|
||||||
|
const auto mock_time = ConsumeTime(fuzzed_data_provider);
|
||||||
|
SetMockTime(mock_time);
|
||||||
|
|
||||||
// fuzzed_data_provider is fully consumed after this call, don't use it
|
// fuzzed_data_provider is fully consumed after this call, don't use it
|
||||||
CDataStream random_bytes_data_stream{fuzzed_data_provider.ConsumeRemainingBytes<unsigned char>(), SER_NETWORK, PROTOCOL_VERSION};
|
CDataStream random_bytes_data_stream{fuzzed_data_provider.ConsumeRemainingBytes<unsigned char>(), SER_NETWORK, PROTOCOL_VERSION};
|
||||||
try {
|
try {
|
||||||
|
@ -36,10 +36,10 @@ FUZZ_TARGET_INIT(process_messages, initialize_process_messages)
|
|||||||
|
|
||||||
ConnmanTestMsg& connman = *(ConnmanTestMsg*)g_setup->m_node.connman.get();
|
ConnmanTestMsg& connman = *(ConnmanTestMsg*)g_setup->m_node.connman.get();
|
||||||
TestChainState& chainstate = *(TestChainState*)&g_setup->m_node.chainman->ActiveChainstate();
|
TestChainState& chainstate = *(TestChainState*)&g_setup->m_node.chainman->ActiveChainstate();
|
||||||
|
SetMockTime(1610000000); // any time to successfully reset ibd
|
||||||
chainstate.ResetIbd();
|
chainstate.ResetIbd();
|
||||||
std::vector<CNode*> peers;
|
|
||||||
bool jump_out_of_ibd{false};
|
|
||||||
|
|
||||||
|
std::vector<CNode*> peers;
|
||||||
const auto num_peers_to_add = fuzzed_data_provider.ConsumeIntegralInRange(1, 3);
|
const auto num_peers_to_add = fuzzed_data_provider.ConsumeIntegralInRange(1, 3);
|
||||||
for (int i = 0; i < num_peers_to_add; ++i) {
|
for (int i = 0; i < num_peers_to_add; ++i) {
|
||||||
peers.push_back(ConsumeNodeAsUniquePtr(fuzzed_data_provider, i).release());
|
peers.push_back(ConsumeNodeAsUniquePtr(fuzzed_data_provider, i).release());
|
||||||
@ -55,10 +55,11 @@ FUZZ_TARGET_INIT(process_messages, initialize_process_messages)
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (fuzzed_data_provider.ConsumeBool()) {
|
while (fuzzed_data_provider.ConsumeBool()) {
|
||||||
if (!jump_out_of_ibd) jump_out_of_ibd = fuzzed_data_provider.ConsumeBool();
|
|
||||||
if (jump_out_of_ibd && chainstate.IsInitialBlockDownload()) chainstate.JumpOutOfIbd();
|
|
||||||
const std::string random_message_type{fuzzed_data_provider.ConsumeBytesAsString(CMessageHeader::COMMAND_SIZE).c_str()};
|
const std::string random_message_type{fuzzed_data_provider.ConsumeBytesAsString(CMessageHeader::COMMAND_SIZE).c_str()};
|
||||||
|
|
||||||
|
const auto mock_time = ConsumeTime(fuzzed_data_provider);
|
||||||
|
SetMockTime(mock_time);
|
||||||
|
|
||||||
CSerializedNetMsg net_msg;
|
CSerializedNetMsg net_msg;
|
||||||
net_msg.command = random_message_type;
|
net_msg.command = random_message_type;
|
||||||
net_msg.data = ConsumeRandomLengthByteVector(fuzzed_data_provider);
|
net_msg.data = ConsumeRandomLengthByteVector(fuzzed_data_provider);
|
||||||
|
Loading…
Reference in New Issue
Block a user