mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-04 15:45:25 +00:00
LibHTTP: Return error if request is incomplete
If there is not enough input to completely parse HTTP request we need to return error and handle it in HTTP server.
This commit is contained in:
committed by
Andreas Kling
parent
9220cdc285
commit
7b8a857e30
@@ -102,6 +102,7 @@ ErrorOr<HttpRequest, HttpRequest::ParseError> HttpRequest::from_raw_request(Read
|
||||
|
||||
Vector<u8, 256> buffer;
|
||||
|
||||
Optional<unsigned> content_length;
|
||||
DeprecatedString method;
|
||||
DeprecatedString resource;
|
||||
DeprecatedString protocol;
|
||||
@@ -168,6 +169,10 @@ ErrorOr<HttpRequest, HttpRequest::ParseError> HttpRequest::from_raw_request(Read
|
||||
}
|
||||
|
||||
commit_and_advance_to(current_header.value, next_state);
|
||||
|
||||
if (current_header.name.equals_ignoring_ascii_case("Content-Length"sv))
|
||||
content_length = current_header.value.to_uint();
|
||||
|
||||
headers.append(move(current_header));
|
||||
break;
|
||||
}
|
||||
@@ -189,6 +194,12 @@ ErrorOr<HttpRequest, HttpRequest::ParseError> HttpRequest::from_raw_request(Read
|
||||
}
|
||||
}
|
||||
|
||||
if (state != State::InBody)
|
||||
return ParseError::RequestIncomplete;
|
||||
|
||||
if (content_length.has_value() && content_length.value() != body.size())
|
||||
return ParseError::RequestIncomplete;
|
||||
|
||||
HttpRequest request;
|
||||
if (method == "GET")
|
||||
request.m_method = Method::GET;
|
||||
|
||||
Reference in New Issue
Block a user