diff options
author | Troy Giorshev <troygiorshev@gmail.com> | 2020-06-08 22:37:55 -0400 |
---|---|---|
committer | Troy Giorshev <troygiorshev@gmail.com> | 2020-09-22 22:01:14 -0400 |
commit | 5bceef6b12fa16d20287693be377dace3dfec3e5 (patch) | |
tree | 0a6fee9b1bdea143702adc97cc01a3a4a2a7928a | |
parent | 1ca20c1af8f08f07c407c3183c37b467ddf0f413 (diff) |
Change CMessageHeader Constructor
This commit removes the single-parameter contructor of CMessageHeader
and replaces it with a default constructor.
The single parameter contructor isn't used anywhere except for tests.
There is no reason to initialize a CMessageHeader with a particular
messagestart. This messagestart should always be replaced when
deserializing an actual message header so that we can run checks on it.
The default constructor initializes it to zero, just like the command
and checksum.
This also removes a parameter of a V1TransportDeserializer constructor,
as it was only used for this purpose.
-rw-r--r-- | src/net.cpp | 2 | ||||
-rw-r--r-- | src/net.h | 3 | ||||
-rw-r--r-- | src/protocol.cpp | 4 | ||||
-rw-r--r-- | src/protocol.h | 2 | ||||
-rw-r--r-- | src/test/fuzz/deserialize.cpp | 2 | ||||
-rw-r--r-- | src/test/fuzz/p2p_transport_deserializer.cpp | 2 |
6 files changed, 7 insertions, 8 deletions
diff --git a/src/net.cpp b/src/net.cpp index fdb76d3b83..1ae4b8fe08 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -2846,7 +2846,7 @@ CNode::CNode(NodeId idIn, ServiceFlags nLocalServicesIn, int nMyStartingHeightIn LogPrint(BCLog::NET, "Added connection peer=%d\n", id); } - m_deserializer = MakeUnique<V1TransportDeserializer>(V1TransportDeserializer(Params().MessageStart(), GetId(), SER_NETWORK, INIT_PROTO_VERSION)); + m_deserializer = MakeUnique<V1TransportDeserializer>(V1TransportDeserializer(GetId(), SER_NETWORK, INIT_PROTO_VERSION)); m_serializer = MakeUnique<V1TransportSerializer>(V1TransportSerializer()); } @@ -765,10 +765,9 @@ private: } public: - V1TransportDeserializer(const CMessageHeader::MessageStartChars& pchMessageStartIn, const NodeId node_id, int nTypeIn, int nVersionIn) + V1TransportDeserializer(const NodeId node_id, int nTypeIn, int nVersionIn) : m_node_id(node_id), hdrbuf(nTypeIn, nVersionIn), - hdr(pchMessageStartIn), vRecv(nTypeIn, nVersionIn) { Reset(); diff --git a/src/protocol.cpp b/src/protocol.cpp index 48ca0c6df6..6b4de68ce9 100644 --- a/src/protocol.cpp +++ b/src/protocol.cpp @@ -84,9 +84,9 @@ const static std::string allNetMessageTypes[] = { }; const static std::vector<std::string> allNetMessageTypesVec(allNetMessageTypes, allNetMessageTypes+ARRAYLEN(allNetMessageTypes)); -CMessageHeader::CMessageHeader(const MessageStartChars& pchMessageStartIn) +CMessageHeader::CMessageHeader() { - memcpy(pchMessageStart, pchMessageStartIn, MESSAGE_START_SIZE); + memset(pchMessageStart, 0, MESSAGE_START_SIZE); memset(pchCommand, 0, sizeof(pchCommand)); nMessageSize = -1; memset(pchChecksum, 0, CHECKSUM_SIZE); diff --git a/src/protocol.h b/src/protocol.h index 7fb84cddf1..3bf0797ca4 100644 --- a/src/protocol.h +++ b/src/protocol.h @@ -37,7 +37,7 @@ public: static constexpr size_t HEADER_SIZE = MESSAGE_START_SIZE + COMMAND_SIZE + MESSAGE_SIZE_SIZE + CHECKSUM_SIZE; typedef unsigned char MessageStartChars[MESSAGE_START_SIZE]; - explicit CMessageHeader(const MessageStartChars& pchMessageStartIn); + explicit CMessageHeader(); /** Construct a P2P message header from message-start characters, a command and the size of the message. * @note Passing in a `pszCommand` longer than COMMAND_SIZE will result in a run-time assertion error. diff --git a/src/test/fuzz/deserialize.cpp b/src/test/fuzz/deserialize.cpp index 54793c890f..f87b7576a4 100644 --- a/src/test/fuzz/deserialize.cpp +++ b/src/test/fuzz/deserialize.cpp @@ -190,7 +190,7 @@ void test_one_input(const std::vector<uint8_t>& buffer) AssertEqualAfterSerializeDeserialize(s); #elif MESSAGEHEADER_DESERIALIZE const CMessageHeader::MessageStartChars pchMessageStart = {0x00, 0x00, 0x00, 0x00}; - CMessageHeader mh(pchMessageStart); + CMessageHeader mh; DeserializeFromFuzzingInput(buffer, mh); (void)mh.IsValid(pchMessageStart); #elif ADDRESS_DESERIALIZE diff --git a/src/test/fuzz/p2p_transport_deserializer.cpp b/src/test/fuzz/p2p_transport_deserializer.cpp index 3e9cd3af38..5349fd3f68 100644 --- a/src/test/fuzz/p2p_transport_deserializer.cpp +++ b/src/test/fuzz/p2p_transport_deserializer.cpp @@ -20,7 +20,7 @@ void initialize() void test_one_input(const std::vector<uint8_t>& buffer) { // Construct deserializer, with a dummy NodeId - V1TransportDeserializer deserializer{Params().MessageStart(), (NodeId)0, SER_NETWORK, INIT_PROTO_VERSION}; + V1TransportDeserializer deserializer{(NodeId)0, SER_NETWORK, INIT_PROTO_VERSION}; const char* pch = (const char*)buffer.data(); size_t n_bytes = buffer.size(); while (n_bytes > 0) { |