mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 11:57:28 -03:00
Merge #17771: tests: Add fuzzing harness for V1TransportDeserializer (P2P transport)
2f63ffd15c
tests: Add fuzzing harness for V1TransportDeserializer (P2P transport) (practicalswift) Pull request description: Add fuzzing harness for `V1TransportDeserializer` (P2P transport). **Testing this PR** Run: ``` $ make distclean $ ./autogen.sh $ CC=clang CXX=clang++ ./configure --enable-fuzz \ --with-sanitizers=address,fuzzer,undefined $ make $ src/test/fuzz/p2p_transport_deserializer … ``` ACKs for top commit: MarcoFalke: ACK2f63ffd15c
Tree-SHA512: 8507d4a0414d16f1b8cc9649e3e638f74071dddc990d7e5d7e6faf77697f50bdaf133e49e2371edd29068a069a074469ef53148c6bfc9950510460b81d87646a
This commit is contained in:
commit
324a6dfeaf
3 changed files with 55 additions and 0 deletions
|
@ -39,6 +39,7 @@ FUZZ_TARGETS = \
|
|||
test/fuzz/messageheader_deserialize \
|
||||
test/fuzz/netaddr_deserialize \
|
||||
test/fuzz/out_point_deserialize \
|
||||
test/fuzz/p2p_transport_deserializer \
|
||||
test/fuzz/parse_hd_keypath \
|
||||
test/fuzz/parse_iso8601 \
|
||||
test/fuzz/parse_numbers \
|
||||
|
@ -452,6 +453,12 @@ test_fuzz_out_point_deserialize_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
|||
test_fuzz_out_point_deserialize_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
||||
test_fuzz_out_point_deserialize_SOURCES = $(FUZZ_SUITE) test/fuzz/deserialize.cpp
|
||||
|
||||
test_fuzz_p2p_transport_deserializer_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||
test_fuzz_p2p_transport_deserializer_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
test_fuzz_p2p_transport_deserializer_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
||||
test_fuzz_p2p_transport_deserializer_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
||||
test_fuzz_p2p_transport_deserializer_SOURCES = $(FUZZ_SUITE) test/fuzz/p2p_transport_deserializer.cpp
|
||||
|
||||
test_fuzz_parse_hd_keypath_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES)
|
||||
test_fuzz_parse_hd_keypath_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
test_fuzz_parse_hd_keypath_LDADD = $(FUZZ_SUITE_LD_COMMON)
|
||||
|
|
47
src/test/fuzz/p2p_transport_deserializer.cpp
Normal file
47
src/test/fuzz/p2p_transport_deserializer.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
// Copyright (c) 2019 The Bitcoin Core developers
|
||||
// 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>
|
||||
|
||||
void initialize()
|
||||
{
|
||||
SelectParams(CBaseChainParams::REGTEST);
|
||||
}
|
||||
|
||||
void test_one_input(const std::vector<uint8_t>& buffer)
|
||||
{
|
||||
V1TransportDeserializer deserializer{Params().MessageStart(), SER_NETWORK, INIT_PROTO_VERSION};
|
||||
const char* pch = (const char*)buffer.data();
|
||||
size_t n_bytes = buffer.size();
|
||||
while (n_bytes > 0) {
|
||||
const int handled = deserializer.Read(pch, n_bytes);
|
||||
if (handled < 0) {
|
||||
break;
|
||||
}
|
||||
pch += handled;
|
||||
n_bytes -= handled;
|
||||
if (deserializer.Complete()) {
|
||||
const int64_t m_time = std::numeric_limits<int64_t>::max();
|
||||
const CNetMessage msg = deserializer.GetMessage(Params().MessageStart(), m_time);
|
||||
assert(msg.m_command.size() <= CMessageHeader::COMMAND_SIZE);
|
||||
assert(msg.m_raw_message_size <= buffer.size());
|
||||
assert(msg.m_raw_message_size == CMessageHeader::HEADER_SIZE + msg.m_message_size);
|
||||
assert(msg.m_time == m_time);
|
||||
if (msg.m_valid_header) {
|
||||
assert(msg.m_valid_netmagic);
|
||||
}
|
||||
if (!msg.m_valid_netmagic) {
|
||||
assert(!msg.m_valid_header);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -30,6 +30,7 @@ FUZZERS_MISSING_CORPORA = [
|
|||
"key_origin_info_deserialize",
|
||||
"merkle_block_deserialize",
|
||||
"out_point_deserialize",
|
||||
"p2p_transport_deserializer",
|
||||
"parse_hd_keypath",
|
||||
"parse_numbers",
|
||||
"parse_script",
|
||||
|
|
Loading…
Reference in a new issue