forked from boostorg/beast
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:
committed by
Vinnie Falco
parent
8c53abe6e5
commit
c7a7d16992
@@ -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))
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user