Skip to content

Commit

Permalink
DynamicBuffer input areas are not mutable
Browse files Browse the repository at this point in the history
fix #1014
  • Loading branch information
vinniefalco committed Feb 21, 2018
1 parent 10ce028 commit d79950d
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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

--------------------------------------------------------------------------------

Expand Down
4 changes: 3 additions & 1 deletion doc/qbk/09_releases.qbk
Expand Up @@ -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.



Expand Down
2 changes: 1 addition & 1 deletion include/boost/beast/core/flat_buffer.hpp
Expand Up @@ -84,7 +84,7 @@ class basic_flat_buffer
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;
Expand Down
2 changes: 1 addition & 1 deletion include/boost/beast/core/flat_static_buffer.hpp
Expand Up @@ -52,7 +52,7 @@ class flat_static_buffer_base
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.
Expand Down
2 changes: 1 addition & 1 deletion include/boost/beast/core/impl/multi_buffer.ipp
Expand Up @@ -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;

Expand Down
23 changes: 22 additions & 1 deletion include/boost/beast/core/impl/static_buffer.ipp
Expand Up @@ -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};
Expand Down
7 changes: 6 additions & 1 deletion include/boost/beast/core/static_buffer.hpp
Expand Up @@ -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 =
Expand Down Expand Up @@ -94,6 +94,11 @@ class static_buffer_base
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.
Expand Down
4 changes: 2 additions & 2 deletions include/boost/beast/websocket/impl/close.ipp
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions include/boost/beast/websocket/impl/read.ipp
Expand Up @@ -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))
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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))
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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()));
Expand Down

0 comments on commit d79950d

Please sign in to comment.