mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-06-28 01:41:57 +02:00
Remove oversized message detection from log and interface
This commit is contained in:
parent
b0e10ff4df
commit
6a91499496
11
src/net.cpp
11
src/net.cpp
@ -577,12 +577,6 @@ bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes, bool& complete
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_deserializer->OversizedMessageDetected()) {
|
|
||||||
LogPrint(BCLog::NET, "Oversized message from peer=%i, disconnecting\n", GetId());
|
|
||||||
m_deserializer->Reset();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
pch += handled;
|
pch += handled;
|
||||||
nBytes -= handled;
|
nBytes -= handled;
|
||||||
|
|
||||||
@ -655,9 +649,10 @@ int V1TransportDeserializer::readHeader(const char *pch, unsigned int nBytes)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// reject messages larger than MAX_SIZE
|
// reject messages larger than MAX_SIZE or MAX_PROTOCOL_MESSAGE_LENGTH
|
||||||
if (hdr.nMessageSize > MAX_SIZE)
|
if (hdr.nMessageSize > MAX_SIZE || hdr.nMessageSize > MAX_PROTOCOL_MESSAGE_LENGTH) {
|
||||||
return -1;
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
// switch state to reading message data
|
// switch state to reading message data
|
||||||
in_data = true;
|
in_data = true;
|
||||||
|
@ -642,8 +642,6 @@ public:
|
|||||||
virtual void Reset() = 0;
|
virtual void Reset() = 0;
|
||||||
// returns true if the current deserialization is complete
|
// returns true if the current deserialization is complete
|
||||||
virtual bool Complete() const = 0;
|
virtual bool Complete() const = 0;
|
||||||
// checks if the potential message in deserialization is oversized
|
|
||||||
virtual bool OversizedMessageDetected() const = 0;
|
|
||||||
// set the serialization context version
|
// set the serialization context version
|
||||||
virtual void SetVersion(int version) = 0;
|
virtual void SetVersion(int version) = 0;
|
||||||
// read and deserialize data
|
// read and deserialize data
|
||||||
@ -695,9 +693,6 @@ public:
|
|||||||
hdrbuf.SetVersion(nVersionIn);
|
hdrbuf.SetVersion(nVersionIn);
|
||||||
vRecv.SetVersion(nVersionIn);
|
vRecv.SetVersion(nVersionIn);
|
||||||
}
|
}
|
||||||
bool OversizedMessageDetected() const {
|
|
||||||
return (in_data && hdr.nMessageSize > MAX_PROTOCOL_MESSAGE_LENGTH);
|
|
||||||
}
|
|
||||||
int Read(const char *pch, unsigned int nBytes) {
|
int Read(const char *pch, unsigned int nBytes) {
|
||||||
return in_data ? readData(pch, nBytes) : readHeader(pch, nBytes);
|
return in_data ? readData(pch, nBytes) : readHeader(pch, nBytes);
|
||||||
}
|
}
|
||||||
|
@ -101,11 +101,10 @@ class InvalidMessagesTest(BitcoinTestFramework):
|
|||||||
msg_over_size = msg_unrecognized(str_data="b" * (valid_data_limit + 1))
|
msg_over_size = msg_unrecognized(str_data="b" * (valid_data_limit + 1))
|
||||||
assert len(msg_over_size.serialize()) == (msg_limit + 1)
|
assert len(msg_over_size.serialize()) == (msg_limit + 1)
|
||||||
|
|
||||||
with node.assert_debug_log(["Oversized message from peer=4, disconnecting"]):
|
# An unknown message type (or *any* message type) over
|
||||||
# An unknown message type (or *any* message type) over
|
# MAX_PROTOCOL_MESSAGE_LENGTH should result in a disconnect.
|
||||||
# MAX_PROTOCOL_MESSAGE_LENGTH should result in a disconnect.
|
node.p2p.send_message(msg_over_size)
|
||||||
node.p2p.send_message(msg_over_size)
|
node.p2p.wait_for_disconnect(timeout=4)
|
||||||
node.p2p.wait_for_disconnect(timeout=4)
|
|
||||||
|
|
||||||
node.disconnect_p2ps()
|
node.disconnect_p2ps()
|
||||||
conn = node.add_p2p_connection(P2PDataStore())
|
conn = node.add_p2p_connection(P2PDataStore())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user