Return 400 if the content-length is invalid (#629)

This commit is contained in:
An Tao 2020-11-18 15:09:25 +08:00 committed by GitHub
parent 72a4cad9c1
commit 4ce2d25d55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -214,7 +214,16 @@ bool HttpRequestParser::parseRequest(MsgBuffer *buf)
request_->getHeaderBy("content-length"); request_->getHeaderBy("content-length");
if (!len.empty()) if (!len.empty())
{ {
currentContentLength_ = std::stoull(len.c_str()); try
{
currentContentLength_ = std::stoull(len.c_str());
}
catch (...)
{
buf->retrieveAll();
shutdownConnection(k400BadRequest);
return false;
}
if (currentContentLength_ == 0) if (currentContentLength_ == 0)
{ {
status_ = HttpRequestParseStatus::kGotAll; status_ = HttpRequestParseStatus::kGotAll;