DynamicBuffer input areas are not mutable

fix #1014
This commit is contained in:
Vinnie Falco
2018-02-21 13:19:14 -08:00
parent 10ce0283c2
commit d79950d95c
9 changed files with 43 additions and 14 deletions

View File

@@ -4,6 +4,7 @@ Version 158:
* Tidy up websocket docs
* Examples set reuse_address(true)
* Advanced servers support clean shutdown via SIGINT or SIGTERM
* DynamicBuffer input areas are not mutable
--------------------------------------------------------------------------------

View File

@@ -156,7 +156,9 @@ to update to the latest Boost release.
* [link beast.ref.boost__beast__websocket__stream.control_callback `websocket::stream::control_callback`]
now copies or moves the function object.
* ([issue 1014]) DynamicBuffer input areas are not mutable.
Actions required: do not attempt to write to input areas of dynamic
buffers.

View File

@@ -84,7 +84,7 @@ public:
using allocator_type = Allocator;
/// The type used to represent the input sequence as a list of buffers.
using const_buffers_type = boost::asio::mutable_buffer;
using const_buffers_type = boost::asio::const_buffer;
/// The type used to represent the output sequence as a list of buffers.
using mutable_buffers_type = boost::asio::mutable_buffer;

View File

@@ -52,7 +52,7 @@ public:
This buffer sequence is guaranteed to have length 1.
*/
using const_buffers_type = boost::asio::mutable_buffer;
using const_buffers_type = boost::asio::const_buffer;
/** The type used to represent the output sequence as a list of buffers.

View File

@@ -132,7 +132,7 @@ class basic_multi_buffer<Allocator>::const_buffers_type
const_buffers_type(basic_multi_buffer const& b);
public:
using value_type = boost::asio::mutable_buffer;
using value_type = boost::asio::const_buffer;
class const_iterator;

View File

@@ -35,9 +35,30 @@ static_buffer_base::
data() const ->
const_buffers_type
{
using boost::asio::mutable_buffer;
using boost::asio::const_buffer;
const_buffers_type result;
if(in_off_ + in_size_ <= capacity_)
{
result[0] = const_buffer{begin_ + in_off_, in_size_};
result[1] = const_buffer{begin_, 0};
}
else
{
result[0] = const_buffer{begin_ + in_off_, capacity_ - in_off_};
result[1] = const_buffer{begin_, in_size_ - (capacity_ - in_off_)};
}
return result;
}
inline
auto
static_buffer_base::
mutable_data() ->
mutable_buffers_type
{
using boost::asio::mutable_buffer;
mutable_buffers_type result;
if(in_off_ + in_size_ <= capacity_)
{
result[0] = mutable_buffer{begin_ + in_off_, in_size_};
result[1] = mutable_buffer{begin_, 0};

View File

@@ -52,7 +52,7 @@ class static_buffer_base
public:
/// The type used to represent the input sequence as a list of buffers.
using const_buffers_type =
std::array<boost::asio::mutable_buffer, 2>;
std::array<boost::asio::const_buffer, 2>;
/// The type used to represent the output sequence as a list of buffers.
using mutable_buffers_type =
@@ -94,6 +94,11 @@ public:
const_buffers_type
data() const;
/** Get a mutable list of buffers that represent the input sequence.
*/
mutable_buffers_type
mutable_data();
/** Get a list of buffers that represent the output sequence, with the given size.
@param size The number of bytes to request.

View File

@@ -228,7 +228,7 @@ operator()(
d.ws.rd_close_ = true;
auto const mb = buffers_prefix(
clamp(d.ws.rd_fh_.len),
d.ws.rd_buf_.data());
d.ws.rd_buf_.mutable_data());
if(d.ws.rd_fh_.len > 0 && d.ws.rd_fh_.mask)
detail::mask_inplace(mb, d.ws.rd_key_);
detail::read_close(d.ws.cr_, mb, d.ev);
@@ -370,7 +370,7 @@ close(close_reason const& cr, error_code& ec)
rd_close_ = true;
auto const mb = buffers_prefix(
clamp(rd_fh_.len),
rd_buf_.data());
rd_buf_.mutable_data());
if(rd_fh_.len > 0 && rd_fh_.mask)
detail::mask_inplace(mb, rd_key_);
detail::read_close(cr_, mb, result);

View File

@@ -253,7 +253,7 @@ operator()(
if(ws_.rd_fh_.len > 0 && ws_.rd_fh_.mask)
detail::mask_inplace(buffers_prefix(
clamp(ws_.rd_fh_.len),
ws_.rd_buf_.data()),
ws_.rd_buf_.mutable_data()),
ws_.rd_key_);
if(detail::is_control(ws_.rd_fh_.op))
{
@@ -440,7 +440,7 @@ operator()(
ws_.rd_buf_.commit(bytes_transferred);
if(ws_.rd_fh_.mask)
detail::mask_inplace(buffers_prefix(clamp(
ws_.rd_remain_), ws_.rd_buf_.data()),
ws_.rd_remain_), ws_.rd_buf_.mutable_data()),
ws_.rd_key_);
}
if(ws_.rd_buf_.size() > 0)
@@ -528,7 +528,7 @@ operator()(
if(ws_.rd_fh_.mask)
detail::mask_inplace(
buffers_prefix(clamp(ws_.rd_remain_),
ws_.rd_buf_.data()), ws_.rd_key_);
ws_.rd_buf_.mutable_data()), ws_.rd_key_);
did_read_ = true;
}
zlib::z_params zs;
@@ -1049,7 +1049,7 @@ loop:
// of the buffer holding payload data.
if(rd_fh_.len > 0 && rd_fh_.mask)
detail::mask_inplace(buffers_prefix(
clamp(rd_fh_.len), rd_buf_.data()),
clamp(rd_fh_.len), rd_buf_.mutable_data()),
rd_key_);
if(detail::is_control(rd_fh_.op))
{
@@ -1151,7 +1151,7 @@ loop:
if(rd_fh_.mask)
detail::mask_inplace(
buffers_prefix(clamp(rd_remain_),
rd_buf_.data()), rd_key_);
rd_buf_.mutable_data()), rd_key_);
}
if(rd_buf_.size() > 0)
{
@@ -1258,7 +1258,7 @@ loop:
if(rd_fh_.mask)
detail::mask_inplace(
buffers_prefix(clamp(rd_remain_),
rd_buf_.data()), rd_key_);
rd_buf_.mutable_data()), rd_key_);
auto const in = buffers_prefix(
clamp(rd_remain_), buffers_front(
rd_buf_.data()));