Skip to content

Commit ba04c4a

Browse files
committed
Limit message sizes before transfer
This introduces a fixed limit for the size of p2p messages, and enforces it before download.
1 parent 84a05b8 commit ba04c4a

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/net.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,11 @@ bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes)
523523
if (handled < 0)
524524
return false;
525525

526+
if (msg.in_data && msg.hdr.nMessageSize > MAX_PROTOCOL_MESSAGE_LENGTH) {
527+
LogPrint("net", "Oversized message from peer=%i, disconnecting", GetId());
528+
return false;
529+
}
530+
526531
pch += handled;
527532
nBytes -= handled;
528533

src/net.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ static const int TIMEOUT_INTERVAL = 20 * 60;
4646
static const unsigned int MAX_INV_SZ = 50000;
4747
/** The maximum number of new addresses to accumulate before announcing. */
4848
static const unsigned int MAX_ADDR_TO_SEND = 1000;
49+
/** Maximum length of incoming protocol messages (no message over 2 MiB is currently acceptable). */
50+
static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 2 * 1024 * 1024;
4951
/** -listen default */
5052
static const bool DEFAULT_LISTEN = true;
5153
/** -upnp default */

0 commit comments

Comments
 (0)