Fix buffer overflow handling for string_body and mutable_body

fix #553, fix #558
This commit is contained in:
octopus-prime
2017-06-29 20:25:16 +02:00
committed by Vinnie Falco
parent c149321013
commit ebfc3f4537
3 changed files with 27 additions and 16 deletions

View File

@@ -5,6 +5,7 @@ Version 71:
* Fix spurious on_chunk invocation * Fix spurious on_chunk invocation
* Call prepare_payload in HTTP example * Call prepare_payload in HTTP example
* Check trailers in test * Check trailers in test
* Fix buffer overflow handling for string_body and mutable_body
WebSockets: WebSockets:

View File

@@ -109,14 +109,21 @@ struct mutable_body
if(*content_length > (std::numeric_limits< if(*content_length > (std::numeric_limits<
std::size_t>::max)()) std::size_t>::max)())
{ {
ec = boost::system::errc::make_error_code( ec = beast::http::error::buffer_overflow;
boost::system::errc::not_enough_memory);
return; return;
} }
ec.assign(0, ec.category()); try
{
body_.reserve(static_cast< body_.reserve(static_cast<
std::size_t>(*content_length)); std::size_t>(*content_length));
} }
catch(std::exception const&)
{
ec = beast::http::error::buffer_overflow;
return;
}
}
ec.assign(0, ec.category());
} }
template<class ConstBufferSequence> template<class ConstBufferSequence>
@@ -132,7 +139,7 @@ struct mutable_body
{ {
body_.resize(len + n); body_.resize(len + n);
} }
catch(std::length_error const&) catch(std::exception const&)
{ {
ec = beast::http::error::buffer_overflow; ec = beast::http::error::buffer_overflow;
return 0; return 0;

View File

@@ -90,19 +90,22 @@ struct string_body
if(*content_length > (std::numeric_limits< if(*content_length > (std::numeric_limits<
std::size_t>::max)()) std::size_t>::max)())
{ {
ec = make_error_code( ec = error::buffer_overflow;
errc::not_enough_memory);
return; return;
} }
ec.assign(0, ec.category()); try
{
body_.reserve(static_cast< body_.reserve(static_cast<
std::size_t>(*content_length)); std::size_t>(*content_length));
} }
else catch(std::exception const&)
{ {
ec.assign(0, ec.category()); ec = error::buffer_overflow;
return;
} }
} }
ec.assign(0, ec.category());
}
template<class ConstBufferSequence> template<class ConstBufferSequence>
std::size_t std::size_t
@@ -117,7 +120,7 @@ struct string_body
{ {
body_.resize(len + n); body_.resize(len + n);
} }
catch(std::length_error const&) catch(std::exception const&)
{ {
ec = error::buffer_overflow; ec = error::buffer_overflow;
return 0; return 0;