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 12:44:28 -07:00
parent c465ed5a69
commit ea35f6f770
3 changed files with 33 additions and 6 deletions
+13 -6
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;