aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPieter Wuille <[email protected]>2015-03-05 04:01:22 -0800
committerRoss Nicoll <[email protected]>2015-06-27 14:15:26 +0000
commitfe3a31384c2df823351a10674cbbfc19ae378316 (patch)
tree26010a20aba408fcc89d57de2961f867893ec7ed /src
parentprevent SOCKET leak in BindListenPort() (diff)
downloaddiscoin-fe3a31384c2df823351a10674cbbfc19ae378316.tar.xz
discoin-fe3a31384c2df823351a10674cbbfc19ae378316.zip
Limit message sizes before transfer
This introduces a fixed limit for the size of p2p messages, and enforces it before download. Rebased-From: ba04c4a7801e7d68a5e84035b919e5c3626eb7a7 Github-Pull: #5843
Diffstat (limited to 'src')
-rw-r--r--src/net.cpp5
-rw-r--r--src/net.h2
2 files changed, 7 insertions, 0 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 97bb52cd3..b6ebf1cee 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -666,6 +666,11 @@ bool CNode::ReceiveMsgBytes(const char *pch, unsigned int nBytes)
if (handled < 0)
return false;
+ if (msg.in_data && msg.hdr.nMessageSize > MAX_PROTOCOL_MESSAGE_LENGTH) {
+ LogPrint("net", "Oversized message from peer=%i, disconnecting", GetId());
+ return false;
+ }
+
pch += handled;
nBytes -= handled;
diff --git a/src/net.h b/src/net.h
index 210f7ca5c..6fc1a8ba6 100644
--- a/src/net.h
+++ b/src/net.h
@@ -43,6 +43,8 @@ static const int PING_INTERVAL = 2 * 60;
static const int TIMEOUT_INTERVAL = 20 * 60;
/** The maximum number of entries in an 'inv' protocol message */
static const unsigned int MAX_INV_SZ = 50000;
+/** Maximum length of incoming protocol messages (no message over 2 MiB is currently acceptable). */
+static const unsigned int MAX_PROTOCOL_MESSAGE_LENGTH = 2 * 1024 * 1024;
/** The maximum number of entries in mapAskFor */
static const size_t MAPASKFOR_MAX_SZ = MAX_INV_SZ;