Allow the use of string_body and vector_body with -fno-exceptions

`string_body` and `vector_body` will no longer translate all exceptions
to "buffer_overflow" error code. `buffer_overflow` error can now only
occur if the Body's max_size() is exceeded.

Changes required:
Code that relies on exceptions thrown from value_type's reserve/resize
being translated into an error code must implement a mechanism to catch
the exception.

Signed-off-by: Damian Jarek <damian.jarek93@gmail.com>
This commit is contained in:
Damian Jarek
2019-03-01 22:55:58 +01:00
committed by Vinnie Falco
parent 8c53abe6e5
commit c7a7d16992
2 changed files with 12 additions and 32 deletions

View File

@@ -15,6 +15,7 @@
#include <boost/beast/http/error.hpp>
#include <boost/beast/http/message.hpp>
#include <boost/beast/core/buffers_range.hpp>
#include <boost/beast/core/detail/clamp.hpp>
#include <boost/beast/core/detail/type_traits.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/optional.hpp>
@@ -94,21 +95,12 @@ public:
{
if(length)
{
if(static_cast<std::size_t>(*length) != *length)
{
ec = error::buffer_overflow;
return;
}
try
{
body_.reserve(
static_cast<std::size_t>(*length));
}
catch(std::exception const&)
if(*length > body_.max_size())
{
ec = error::buffer_overflow;
return;
}
body_.reserve(beast::detail::clamp(*length));
}
ec = {};
}
@@ -120,15 +112,13 @@ public:
{
auto const extra = buffer_size(buffers);
auto const size = body_.size();
try
{
body_.resize(size + extra);
}
catch(std::exception const&)
if (extra > body_.max_size() - size)
{
ec = error::buffer_overflow;
return 0;
}
body_.resize(size + extra);
ec = {};
CharT* dest = &body_[size];
for(auto b : beast::buffers_range_ref(buffers))

View File

@@ -14,6 +14,7 @@
#include <boost/beast/core/buffer_size.hpp>
#include <boost/beast/http/error.hpp>
#include <boost/beast/http/message.hpp>
#include <boost/beast/core/detail/clamp.hpp>
#include <boost/beast/core/detail/type_traits.hpp>
#include <boost/asio/buffer.hpp>
#include <boost/optional.hpp>
@@ -88,21 +89,12 @@ public:
{
if(length)
{
if(static_cast<std::size_t>(*length) != *length)
{
ec = error::buffer_overflow;
return;
}
try
{
body_.reserve(
static_cast<std::size_t>(*length));
}
catch(std::exception const&)
if(*length > body_.max_size())
{
ec = error::buffer_overflow;
return;
}
body_.reserve(beast::detail::clamp(*length));
}
ec = {};
}
@@ -114,15 +106,13 @@ public:
{
auto const n = buffer_size(buffers);
auto const len = body_.size();
try
{
body_.resize(len + n);
}
catch(std::exception const&)
if (n > body_.max_size() - len)
{
ec = error::buffer_overflow;
return 0;
}
body_.resize(len + n);
ec = {};
return net::buffer_copy(net::buffer(
&body_[0] + len, n), buffers);