Due to changes to the functions V1TransportDeserializer::readHeader
and V1TransportDeserializer::GetMessage
, the “Fuzzing the Bitcoin Core P2P layer using Honggfuzz NetDriver” section in fuzzing.md
is outdated. The git apply
command doesn’t work.
0$ git apply << "EOF"
1diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp
2index 455a82e39..2faa3f80f 100644
3--- a/src/bitcoind.cpp
4+++ b/src/bitcoind.cpp
5@@ -158,7 +158,11 @@ static bool AppInit(int argc, char* argv[])
6 return fRet;
7 }
8
9+#ifdef HFND_FUZZING_ENTRY_FUNCTION_CXX
10+HFND_FUZZING_ENTRY_FUNCTION_CXX(int argc, char* argv[])
11+#else
12 int main(int argc, char* argv[])
13+#endif
14 {
15 #ifdef WIN32
16 util::WinCmdLineArgs winArgs;
17diff --git a/src/net.cpp b/src/net.cpp
18index cf987b699..636a4176a 100644
19--- a/src/net.cpp
20+++ b/src/net.cpp
21@@ -709,7 +709,7 @@ int V1TransportDeserializer::readHeader(const char *pch, unsigned int nBytes)
22 }
23
24 // Check start string, network magic
25- if (memcmp(hdr.pchMessageStart, m_chain_params.MessageStart(), CMessageHeader::MESSAGE_START_SIZE) != 0) {
26+ if (false && memcmp(hdr.pchMessageStart, m_chain_params.MessageStart(), CMessageHeader::MESSAGE_START_SIZE) != 0) { // skip network magic checking
27 LogPrint(BCLog::NET, "HEADER ERROR - MESSAGESTART (%s, %u bytes), received %s, peer=%d\n", hdr.GetCommand(), hdr.nMessageSize, HexStr(hdr.pchMessageStart), m_node_id);
28 return -1;
29 }
30@@ -768,7 +768,7 @@ Optional<CNetMessage> V1TransportDeserializer::GetMessage(const std::chrono::mic
31 RandAddEvent(ReadLE32(hash.begin()));
32
33 // Check checksum and header command string
34- if (memcmp(hash.begin(), hdr.pchChecksum, CMessageHeader::CHECKSUM_SIZE) != 0) {
35+ if (false && memcmp(hash.begin(), hdr.pchChecksum, CMessageHeader::CHECKSUM_SIZE) != 0) { // skip checksum checking
36 LogPrint(BCLog::NET, "CHECKSUM ERROR (%s, %u bytes), expected %s was %s, peer=%d\n",
37 SanitizeString(msg->m_command), msg->m_message_size,
38 HexStr(Span<uint8_t>(hash.begin(), hash.begin() + CMessageHeader::CHECKSUM_SIZE)),
39EOF