From 45004022ad994e78ec0210aa969033e11dad3500 Mon Sep 17 00:00:00 2001 From: Michiel Visser Date: Wed, 16 Feb 2022 11:51:04 +0100 Subject: [PATCH] LibProtocol: Fix crash on EOF when using Request::stream_into `Request::stream_into_impl` would call `stream.write_or_error` with a zero length buffer when EOF was reached. However, the `Core::Stream::Stream::write_or_error` implementation verifies that the buffer lenght is non-zero, resulting in a crash. With this change the zero length buffer is never written to the stream. --- Userland/Libraries/LibProtocol/Request.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibProtocol/Request.cpp b/Userland/Libraries/LibProtocol/Request.cpp index 35b7cbb2c7..bf506c2582 100644 --- a/Userland/Libraries/LibProtocol/Request.cpp +++ b/Userland/Libraries/LibProtocol/Request.cpp @@ -52,12 +52,12 @@ void Request::stream_into_impl(T& stream) if (result.is_error()) continue; auto nread = result.value(); + if (nread == 0) + break; if (!stream.write_or_error({ buf, nread })) { // FIXME: What do we do here? TODO(); } - if (nread == 0) - break; } while (true); if (m_internal_stream_data->read_stream->is_eof() && m_internal_stream_data->request_done) {