Ignore Content-Length in some cases:

fix #692

The value of Content-Length is not checked for limits
when the semantics of an HTTP response indicate that
the message has no body. For example, when status is 101.
This commit is contained in:
Vinnie Falco
2017-07-29 05:24:44 -07:00
parent c465ed5a69
commit ea35f6f770
3 changed files with 33 additions and 6 deletions

View File

@@ -3,6 +3,7 @@ Version 92:
* Fix typo in test/CMakeLists.txt
* basic_fields::value_type is not copyable
* Update repository links in source comments
* Ignore Content-Length in some cases
--------------------------------------------------------------------------------

View File

@@ -532,6 +532,11 @@ finish_header(error_code& ec, std::true_type)
}
else if(f_ & flagContentLength)
{
if(len_ > body_limit_)
{
ec = error::body_limit;
return;
}
if(len_ > 0)
{
f_ |= flagHasBody;
@@ -578,12 +583,20 @@ finish_header(error_code& ec, std::false_type)
status_ == 204 || // No Content
status_ == 304) // Not Modified
{
// VFALCO Content-Length may be present, but we
// treat the message as not having a body.
// https://github.com/boostorg/beast/issues/692
state_ = state::complete;
return;
}
if(f_ & flagContentLength)
{
if(len_ > body_limit_)
{
ec = error::body_limit;
return;
}
if(len_ > 0)
{
f_ |= flagHasBody;
@@ -876,12 +889,6 @@ do_field(field f,
return;
}
if(v > body_limit_)
{
ec = error::body_limit;
return;
}
ec.assign(0, ec.category());
len_ = v;
f_ |= flagContentLength;

View File

@@ -1106,6 +1106,24 @@ public:
});
}
// https://github.com/boostorg/beast/issues/692
void
testIssue692()
{
error_code ec;
test_parser<false> p;
p.eager(true);
string_view s =
"HTTP/1.1 101 Switching Protocols\r\n"
"Content-Length: 2147483648\r\n"
"\r\n";
p.put(boost::asio::buffer(
s.data(), s.size()), ec);
if(! BEAST_EXPECTS(! ec, ec.message()))
return;
BEAST_EXPECT(p.is_done());
}
//--------------------------------------------------------------------------
void
@@ -1216,6 +1234,7 @@ public:
testIssue430();
testIssue452();
testIssue496();
testIssue692();
testFuzz();
testRegression1();
}