From 2b14fdae11cb7aed25eea83638f7323b14c2b185 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Mon, 28 Oct 2024 16:34:21 -0400 Subject: [PATCH] Upgrade uWebSockets to v20.70.0 Signed-off-by: Juan Cruz Viotti --- DEPENDENCIES | 2 +- vendor/uwebsockets.mask | 1 + vendor/uwebsockets/src/AsyncSocketData.h | 1 + vendor/uwebsockets/src/HttpParser.h | 22 ++++++++++++++++++---- vendor/uwebsockets/src/TopicTree.h | 1 + 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/DEPENDENCIES b/DEPENDENCIES index 532b72d5..57c7cf09 100644 --- a/DEPENDENCIES +++ b/DEPENDENCIES @@ -3,6 +3,6 @@ noa https://github.com/sourcemeta/noa caad2e1ceedf9fd1a18686a6a6d1e2b9757ead75 jsontoolkit https://github.com/sourcemeta/jsontoolkit 2d78929faf0f96110edfb67fa3ddf6916cf35ef7 bearssl https://www.bearssl.org/git/BearSSL 8ef7680081c61b486622f2d983c0d3d21e83caad zlib https://github.com/madler/zlib 51b7f2abdade71cd9bb0e7a373ef2610ec6f9daf -uwebsockets https://github.com/uNetworking/uWebSockets v20.69.0 +uwebsockets https://github.com/uNetworking/uWebSockets v20.70.0 googletest https://github.com/google/googletest 987e225614755fec7253aa95bf959c09e0d380d7 curl https://github.com/curl/curl curl-8_10_1 diff --git a/vendor/uwebsockets.mask b/vendor/uwebsockets.mask index 13503db6..11e6317c 100644 --- a/vendor/uwebsockets.mask +++ b/vendor/uwebsockets.mask @@ -22,3 +22,4 @@ uSockets/.gitmodules uSockets/Makefile uSockets/module.modulemap uSockets/README.md +h1spec diff --git a/vendor/uwebsockets/src/AsyncSocketData.h b/vendor/uwebsockets/src/AsyncSocketData.h index b72b2c10..85fbb688 100644 --- a/vendor/uwebsockets/src/AsyncSocketData.h +++ b/vendor/uwebsockets/src/AsyncSocketData.h @@ -47,6 +47,7 @@ struct BackPressure { void clear() { pendingRemoval = 0; buffer.clear(); + buffer.shrink_to_fit(); } void reserve(size_t length) { buffer.reserve(length + pendingRemoval); diff --git a/vendor/uwebsockets/src/HttpParser.h b/vendor/uwebsockets/src/HttpParser.h index b94aa33e..18e58b93 100644 --- a/vendor/uwebsockets/src/HttpParser.h +++ b/vendor/uwebsockets/src/HttpParser.h @@ -290,12 +290,15 @@ struct HttpParser { } /* Puts method as key, target as value and returns non-null (or nullptr on error). */ - static inline char *consumeRequestLine(char *data, HttpRequest::Header &header) { + static inline char *consumeRequestLine(char *data, char *end, HttpRequest::Header &header) { /* Scan until single SP, assume next is / (origin request) */ char *start = data; /* This catches the post padded CR and fails */ while (data[0] > 32) data++; - if (data[0] == 32 && data[1] == '/') { + if (&data[1] == end) [[unlikely]] { + return nullptr; + } + if (data[0] == 32 && data[1] == '/') [[likely]] { header.key = {start, (size_t) (data - start)}; data++; /* Scan for less than 33 (catches post padded CR and fails) */ @@ -308,6 +311,13 @@ struct HttpParser { /* Now we stand on space */ header.value = {start, (size_t) (data - start)}; /* Check that the following is http 1.1 */ + if (data + 11 >= end) { + /* Whatever we have must be part of the version string */ + if (memcmp(" HTTP/1.1\r\n", data, std::min(11, (unsigned int) (end - data))) == 0) { + return nullptr; + } + return (char *) 0x1; + } if (memcmp(" HTTP/1.1\r\n", data, 11) == 0) { return data + 11; } @@ -373,7 +383,7 @@ struct HttpParser { * which is then removed, and our counters to flip due to overflow and we end up with a crash */ /* The request line is different from the field names / field values */ - if ((char *) 2 > (postPaddedBuffer = consumeRequestLine(postPaddedBuffer, headers[0]))) { + if ((char *) 2 > (postPaddedBuffer = consumeRequestLine(postPaddedBuffer, end, headers[0]))) { /* Error - invalid request line */ /* Assuming it is 505 HTTP Version Not Supported */ err = postPaddedBuffer ? HTTP_ERROR_505_HTTP_VERSION_NOT_SUPPORTED : 0; @@ -389,6 +399,10 @@ struct HttpParser { /* We should not accept whitespace between key and colon, so colon must foloow immediately */ if (postPaddedBuffer[0] != ':') { + /* If we stand at the end, we are fragmented */ + if (postPaddedBuffer == end) { + return 0; + } /* Error: invalid chars in field name */ err = HTTP_ERROR_400_BAD_REQUEST; return 0; @@ -439,7 +453,7 @@ struct HttpParser { return (unsigned int) ((postPaddedBuffer + 2) - start); } else { /* \r\n\r plus non-\n letter is malformed request, or simply out of search space */ - if (postPaddedBuffer != end) { + if (postPaddedBuffer + 1 < end) { err = HTTP_ERROR_400_BAD_REQUEST; } return 0; diff --git a/vendor/uwebsockets/src/TopicTree.h b/vendor/uwebsockets/src/TopicTree.h index 88788a69..67a9a161 100644 --- a/vendor/uwebsockets/src/TopicTree.h +++ b/vendor/uwebsockets/src/TopicTree.h @@ -30,6 +30,7 @@ #include #include #include +#include namespace uWS {