#2207 Fixed regression in HTTP parser.

This commit is contained in:
XMRig 2021-04-10 21:02:59 +07:00
parent 3c6077fb02
commit 30cfcc27db
No known key found for this signature in database
GPG key ID: 446A53638BE94409
5 changed files with 7 additions and 14 deletions

View file

@ -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);
}
}

View file

@ -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;
}

View file

@ -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);

View file

@ -50,14 +50,7 @@ void xmrig::HttpServer::onConnection(uv_stream_t *stream, uint16_t)
{
auto ctx = static_cast<HttpContext*>(tcp->data);
if (nread >= 0) {
const auto size = static_cast<size_t>(nread);
const auto parsed = ctx->parse(buf->base, size);
if (parsed < size) {
ctx->close();
}
} else {
if (nread < 0 || !ctx->parse(buf->base, static_cast<size_t>(nread))) {
ctx->close();
}

View file

@ -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();
}
}