Fix 'no TLS' problem with RequestWithoutContentLengthOrTransferEncoding

This commit is contained in:
yhirose committed 2026-02-10 23:21:43 -10:00
1 parent 1f1a799d13
commit 02e4c53685
2 files changed
+21 -13

No files matched your search

+18 -13
View File
@@ -9869,20 +9869,25 @@ inline bool Server::read_content_core(
payload_max_length_ < (std::numeric_limits<size_t>::max)()) { payload_max_length_ < (std::numeric_limits<size_t>::max)()) {
socket_t s = strm.socket(); socket_t s = strm.socket();
if (s != INVALID_SOCKET) { if (s != INVALID_SOCKET) {
// Peek to check if there is any pending data // Use a non-blocking check to see if there is any pending data.
char peekbuf[1]; // A blocking recv(MSG_PEEK) would deadlock when the client is
ssize_t n = ::recv(s, peekbuf, 1, MSG_PEEK); // waiting for the response (e.g. POST with Connection: close and
if (n > 0) { // no body).
// There is data, so read it with payload limit enforcement if (detail::select_read(s, 0, 0) > 0) {
auto result = detail::read_content_without_length( char peekbuf[1];
strm, payload_max_length_, out); ssize_t n = ::recv(s, peekbuf, 1, MSG_PEEK);
if (result == detail::ReadContentResult::PayloadTooLarge) { if (n > 0) {
res.status = StatusCode::PayloadTooLarge_413; // There is data, so read it with payload limit enforcement
return false; auto result = detail::read_content_without_length(
} else if (result != detail::ReadContentResult::Success) { strm, payload_max_length_, out);
return false; if (result == detail::ReadContentResult::PayloadTooLarge) {
res.status = StatusCode::PayloadTooLarge_413;
return false;
} else if (result != detail::ReadContentResult::Success) {
return false;
}
return true;
} }
return true;
} }
} }
} }
+3
View File
@@ -13,6 +13,9 @@ mbedtls:
@(cd test && make test_mbedtls && LSAN_OPTIONS=suppressions=lsan_suppressions.txt ./test_mbedtls) @(cd test && make test_mbedtls && LSAN_OPTIONS=suppressions=lsan_suppressions.txt ./test_mbedtls)
@(cd test && make proxy_mbedtls) @(cd test && make proxy_mbedtls)
no_tls:
@(cd test && make test_no_tls && ./test_no_tls)
fuzz: fuzz:
@(cd test && make fuzz_test) @(cd test && make fuzz_test)