2020-12-31 05:48:25 -03:00
|
|
|
// Copyright (c) 2019-2020 The Bitcoin Core developers
|
2019-12-18 13:25:20 -03:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include <chainparams.h>
|
|
|
|
#include <net.h>
|
|
|
|
#include <protocol.h>
|
|
|
|
#include <test/fuzz/fuzz.h>
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstdint>
|
|
|
|
#include <limits>
|
|
|
|
#include <vector>
|
|
|
|
|
2020-12-03 12:42:49 -03:00
|
|
|
void initialize_p2p_transport_deserializer()
|
2019-12-18 13:25:20 -03:00
|
|
|
{
|
|
|
|
SelectParams(CBaseChainParams::REGTEST);
|
|
|
|
}
|
|
|
|
|
2020-12-03 12:42:49 -03:00
|
|
|
FUZZ_TARGET_INIT(p2p_transport_deserializer, initialize_p2p_transport_deserializer)
|
2019-12-18 13:25:20 -03:00
|
|
|
{
|
2020-06-29 14:09:42 -04:00
|
|
|
// Construct deserializer, with a dummy NodeId
|
2020-06-08 22:26:22 -04:00
|
|
|
V1TransportDeserializer deserializer{Params(), (NodeId)0, SER_NETWORK, INIT_PROTO_VERSION};
|
2020-11-20 06:16:10 -03:00
|
|
|
Span<const uint8_t> msg_bytes{buffer};
|
2020-09-30 12:08:26 -03:00
|
|
|
while (msg_bytes.size() > 0) {
|
|
|
|
const int handled = deserializer.Read(msg_bytes);
|
2019-12-18 13:25:20 -03:00
|
|
|
if (handled < 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (deserializer.Complete()) {
|
2020-04-14 13:24:18 -04:00
|
|
|
const std::chrono::microseconds m_time{std::numeric_limits<int64_t>::max()};
|
2020-06-29 14:15:06 -04:00
|
|
|
uint32_t out_err_raw_size{0};
|
2020-06-08 22:26:22 -04:00
|
|
|
Optional<CNetMessage> result{deserializer.GetMessage(m_time, out_err_raw_size)};
|
2020-06-29 14:15:06 -04:00
|
|
|
if (result) {
|
|
|
|
assert(result->m_command.size() <= CMessageHeader::COMMAND_SIZE);
|
|
|
|
assert(result->m_raw_message_size <= buffer.size());
|
|
|
|
assert(result->m_raw_message_size == CMessageHeader::HEADER_SIZE + result->m_message_size);
|
|
|
|
assert(result->m_time == m_time);
|
2019-12-18 13:25:20 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|