Skip to content

Commit

Permalink
LibHTTP: Handle running out of input between chunk body and ending CRLF
Browse files Browse the repository at this point in the history
Fixes an issue where LibHTTP would incorrectly detect an end of stream
when it runs out of TLS application data between the chunk body and its
ending CRLF.
  • Loading branch information
alimpfard authored and awesomekling committed Apr 12, 2021
1 parent d7f947b commit 7c98a6b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
15 changes: 11 additions & 4 deletions Userland/Libraries/LibHTTP/Job.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ void Job::on_socket_connected()
if (remaining == -1) {
// read size
auto size_data = read_line(PAGE_SIZE);
if (m_should_read_chunk_ending_line) {
VERIFY(size_data.is_empty());
m_should_read_chunk_ending_line = false;
return IterationDecision::Continue;
}
auto size_lines = size_data.view().lines();
dbgln_if(JOB_DEBUG, "Job: Received a chunk with size '{}'", size_data);
if (size_lines.size() == 0) {
Expand Down Expand Up @@ -327,10 +332,12 @@ void Job::on_socket_connected()

// we've read everything, now let's get the next chunk
size = -1;
[[maybe_unused]] auto line = read_line(PAGE_SIZE);

if constexpr (JOB_DEBUG)
dbgln("Line following (should be empty): '{}'", line);
if (can_read_line()) {
auto line = read_line(PAGE_SIZE);
VERIFY(line.is_empty());
} else {
m_should_read_chunk_ending_line = true;
}
}
m_current_chunk_remaining_size = size;
}
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibHTTP/Job.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class Job : public Core::NetworkJob {
Optional<ssize_t> m_current_chunk_remaining_size;
Optional<size_t> m_current_chunk_total_size;
bool m_can_stream_response { true };
bool m_should_read_chunk_ending_line { false };
};

}

0 comments on commit 7c98a6b

Please sign in to comment.