From 30cfcc27db0db3c4d0cdedfff1ca404c3b06818b Mon Sep 17 00:00:00 2001 From: XMRig Date: Sat, 10 Apr 2021 21:02:59 +0700 Subject: [PATCH] #2207 Fixed regression in HTTP parser. --- src/base/net/http/HttpClient.cpp | 2 +- src/base/net/http/HttpContext.cpp | 6 +++--- src/base/net/http/HttpContext.h | 2 +- src/base/net/http/HttpServer.cpp | 9 +-------- src/base/net/https/HttpsContext.cpp | 2 +- 5 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/base/net/http/HttpClient.cpp b/src/base/net/http/HttpClient.cpp index 96f3f5563..3b1e5ad3b 100644 --- a/src/base/net/http/HttpClient.cpp +++ b/src/base/net/http/HttpClient.cpp @@ -119,7 +119,7 @@ void xmrig::HttpClient::handshake() void xmrig::HttpClient::read(const char *data, size_t size) { - if (parse(data, size) < size) { + if (!parse(data, size)) { close(UV_EPROTO); } } diff --git a/src/base/net/http/HttpContext.cpp b/src/base/net/http/HttpContext.cpp index 92c54c68c..948873c9a 100644 --- a/src/base/net/http/HttpContext.cpp +++ b/src/base/net/http/HttpContext.cpp @@ -118,13 +118,13 @@ bool xmrig::HttpContext::isRequest() const } -size_t xmrig::HttpContext::parse(const char *data, size_t size) +bool xmrig::HttpContext::parse(const char *data, size_t size) { if (size == 0) { - return size; + return true; } - return llhttp_execute(m_parser, data, size); + return llhttp_execute(m_parser, data, size) == HPE_OK; } diff --git a/src/base/net/http/HttpContext.h b/src/base/net/http/HttpContext.h index 81248f28a..9178cf7c3 100644 --- a/src/base/net/http/HttpContext.h +++ b/src/base/net/http/HttpContext.h @@ -62,7 +62,7 @@ public: void write(std::string &&data, bool close) override; bool isRequest() const override; - size_t parse(const char *data, size_t size); + bool parse(const char *data, size_t size); std::string ip() const override; uint64_t elapsed() const; void close(int status = 0); diff --git a/src/base/net/http/HttpServer.cpp b/src/base/net/http/HttpServer.cpp index 3b7e6ef1f..aab750039 100644 --- a/src/base/net/http/HttpServer.cpp +++ b/src/base/net/http/HttpServer.cpp @@ -50,14 +50,7 @@ void xmrig::HttpServer::onConnection(uv_stream_t *stream, uint16_t) { auto ctx = static_cast(tcp->data); - if (nread >= 0) { - const auto size = static_cast(nread); - const auto parsed = ctx->parse(buf->base, size); - - if (parsed < size) { - ctx->close(); - } - } else { + if (nread < 0 || !ctx->parse(buf->base, static_cast(nread))) { ctx->close(); } diff --git a/src/base/net/https/HttpsContext.cpp b/src/base/net/https/HttpsContext.cpp index ba38e18de..3b0ff79af 100644 --- a/src/base/net/https/HttpsContext.cpp +++ b/src/base/net/https/HttpsContext.cpp @@ -74,7 +74,7 @@ bool xmrig::HttpsContext::write(BIO *bio) void xmrig::HttpsContext::parse(char *data, size_t size) { - if (HttpContext::parse(data, size) < size) { + if (!HttpContext::parse(data, size)) { close(); } }