Fix missing check for error code after header is parsed:

The missing error check leads to completely ignoring the body limit,
as the body limit is compared to the "Content-Length" header inside
the "finish_header" method.

closes #2201
This commit is contained in:
Michael Haubenschild
2021-03-18 21:05:04 +01:00
committed by Richard Hodges
parent 26e9a4c294
commit 31a1fb332a
4 changed files with 24 additions and 1 deletions

View File

@ -1,4 +1,5 @@
* Fix case where inflated content is larger than out buffer.
* Fix missing check for error code after header is parsed.
* Fix case where inflated content is larger than the out buffer.
--------------------------------------------------------------------------------

View File

@ -164,6 +164,8 @@ loop:
goto done;
}
finish_header(ec, is_request{});
if(ec)
goto done;
break;
case state::body0:

View File

@ -1517,6 +1517,23 @@ public:
BEAST_EXPECTS(!ec, ec.message());
}
void
testIssue2201()
{
const char data[] =
"HTTP/1.1 200 OK\r\n"
"Content-Length: 5\r\n"
"\r\n"
"*****";
test_parser<false> p;
p.eager(true);
p.body_limit(3);
error_code ec;
p.put(net::buffer(data, strlen(data)), ec);
BEAST_EXPECT(ec == error::body_limit);
}
//--------------------------------------------------------------------------
void
@ -1546,6 +1563,7 @@ public:
testChunkedOverflow();
testChunkedBodySize();
testUnlimitedBody();
testIssue2201();
}
};

View File

@ -104,6 +104,8 @@ public:
boost::optional<std::uint64_t> const& content_length_,
error_code& ec)
{
// The real implementation clears out the error code in basic_string_body::reader::init
ec = {};
++got_on_body;
got_content_length =
static_cast<bool>(content_length_);