From a5089638ea5e15fb8d6e2ac557a842d2809479a6 Mon Sep 17 00:00:00 2001 From: XMRig Date: Tue, 17 Dec 2019 03:18:25 +0700 Subject: [PATCH] #1421 Added limit for maximum send buffer size. --- src/base/net/stratum/Client.cpp | 7 +++++++ src/base/net/stratum/Client.h | 12 ++++-------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/base/net/stratum/Client.cpp b/src/base/net/stratum/Client.cpp index ab4935850..a995bef38 100644 --- a/src/base/net/stratum/Client.cpp +++ b/src/base/net/stratum/Client.cpp @@ -159,6 +159,13 @@ int64_t xmrig::Client::send(const rapidjson::Value &obj) obj.Accept(writer); const size_t size = buffer.GetSize(); + if (size > kMaxSendBufferSize) { + LOG_ERR("[%s] send failed: \"max send buffer size exceeded: %zu\"", url(), size); + close(); + + return -1; + } + if (size > (m_sendBuf.size() - 2)) { m_sendBuf.resize(((size + 1) / 1024 + 1) * 1024); } diff --git a/src/base/net/stratum/Client.h b/src/base/net/stratum/Client.h index 4db21219d..1949e61f3 100644 --- a/src/base/net/stratum/Client.h +++ b/src/base/net/stratum/Client.h @@ -60,14 +60,10 @@ class Client : public BaseClient, public IDnsListener, public ILineListener public: XMRIG_DISABLE_COPY_MOVE_DEFAULT(Client) - constexpr static uint64_t kConnectTimeout = 20 * 1000; - constexpr static uint64_t kResponseTimeout = 20 * 1000; - -# ifdef XMRIG_FEATURE_TLS - constexpr static size_t kInputBufferSize = 1024 * 16; -# else - constexpr static size_t kInputBufferSize = 1024 * 2; -# endif + constexpr static uint64_t kConnectTimeout = 20 * 1000; + constexpr static uint64_t kResponseTimeout = 20 * 1000; + constexpr static size_t kInputBufferSize = 1024 * 16; + constexpr static size_t kMaxSendBufferSize = 1024 * 16; Client(int id, const char *agent, IClientListener *listener); ~Client() override;