mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-07 08:39:22 +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:
parent
9220cdc285
commit
7b8a857e30
Notes:
sideshowbarker
2024-07-17 07:43:44 +09:00
Author: https://github.com/kalenikaliaksandr
Commit: 7b8a857e30
Pull-request: https://github.com/SerenityOS/serenity/pull/18002
Reviewed-by: https://github.com/awesomekling
2 changed files with 14 additions and 0 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue