mirror of
https://github.com/boostorg/beast.git
synced 2025-07-29 20:37:31 +02:00
Fix UB in websocket read tests
An object returned from a function is not guaranteed not to be copied in C++14 or earlier, using `initializer_list` removes the reliance on RVO to work. Signed-off-by: Damian Jarek <damian.jarek93@gmail.com>
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
Version 261:
|
||||
|
||||
* Deduplicate `websocket::read_size_hint` definition
|
||||
* Fix UB in websocket read tests
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
@ -133,7 +133,7 @@ public:
|
||||
[&](ws_type_t<deflateSupported>& ws)
|
||||
{
|
||||
put(ws.next_layer().buffer(), cbuf(
|
||||
0x89, 0x00));
|
||||
{0x89, 0x00}));
|
||||
bool invoked = false;
|
||||
ws.control_callback(
|
||||
[&](frame_type kind, string_view)
|
||||
@ -155,7 +155,7 @@ public:
|
||||
[&](ws_type_t<deflateSupported>& ws)
|
||||
{
|
||||
put(ws.next_layer().buffer(), cbuf(
|
||||
0x88, 0x00));
|
||||
{0x88, 0x00}));
|
||||
bool invoked = false;
|
||||
ws.control_callback(
|
||||
[&](frame_type kind, string_view)
|
||||
@ -313,7 +313,7 @@ public:
|
||||
[&](ws_type_t<deflateSupported>& ws)
|
||||
{
|
||||
w.write_raw(ws, cbuf(
|
||||
0x8f, 0x80, 0xff, 0xff, 0xff, 0xff));
|
||||
{0x8f, 0x80, 0xff, 0xff, 0xff, 0xff}));
|
||||
doReadTest(w, ws, close_code::protocol_error);
|
||||
});
|
||||
|
||||
@ -322,7 +322,7 @@ public:
|
||||
[&](ws_type_t<deflateSupported>& ws)
|
||||
{
|
||||
put(ws.next_layer().buffer(), cbuf(
|
||||
0x88, 0x02, 0x03, 0xed));
|
||||
{0x88, 0x02, 0x03, 0xed}));
|
||||
doFailTest(w, ws, error::bad_close_code);
|
||||
});
|
||||
|
||||
@ -332,8 +332,8 @@ public:
|
||||
{
|
||||
w.write_some(ws, false, sbuf("*"));
|
||||
w.write_raw(ws, cbuf(
|
||||
0x80, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff));
|
||||
{0x80, 0xff, 0xff, 0xff, 0xff, 0xff,
|
||||
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}));
|
||||
doReadTest(w, ws, close_code::too_big);
|
||||
});
|
||||
|
||||
@ -351,7 +351,7 @@ public:
|
||||
[&](ws_type_t<deflateSupported>& ws)
|
||||
{
|
||||
put(ws.next_layer().buffer(), cbuf(
|
||||
0x81, 0x06, 0x03, 0xea, 0xf0, 0x28, 0x8c, 0xbc));
|
||||
{0x81, 0x06, 0x03, 0xea, 0xf0, 0x28, 0x8c, 0xbc}));
|
||||
doFailTest(w, ws, error::bad_frame_payload);
|
||||
});
|
||||
|
||||
|
@ -12,7 +12,6 @@
|
||||
|
||||
#include <boost/beast/core/bind_handler.hpp>
|
||||
#include <boost/beast/core/buffer_traits.hpp>
|
||||
#include <boost/beast/core/buffers_prefix.hpp>
|
||||
#include <boost/beast/core/buffers_to_string.hpp>
|
||||
#include <boost/beast/core/ostream.hpp>
|
||||
#include <boost/beast/core/multi_buffer.hpp>
|
||||
@ -22,9 +21,7 @@
|
||||
#include <boost/beast/_experimental/unit_test/suite.hpp>
|
||||
#include <boost/asio/executor_work_guard.hpp>
|
||||
#include <boost/asio/io_context.hpp>
|
||||
#include <boost/asio/spawn.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <array>
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
#include <random>
|
||||
@ -377,42 +374,9 @@ public:
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
template<std::size_t N>
|
||||
class cbuf_helper
|
||||
net::const_buffer cbuf(std::initializer_list<std::uint8_t> bytes)
|
||||
{
|
||||
std::array<std::uint8_t, N> v_;
|
||||
net::const_buffer cb_;
|
||||
|
||||
public:
|
||||
using value_type = decltype(cb_);
|
||||
using const_iterator = value_type const*;
|
||||
|
||||
template<class... Vn>
|
||||
explicit
|
||||
cbuf_helper(Vn... vn)
|
||||
: v_({{ static_cast<std::uint8_t>(vn)... }})
|
||||
, cb_(v_.data(), v_.size())
|
||||
{
|
||||
}
|
||||
|
||||
const_iterator
|
||||
begin() const
|
||||
{
|
||||
return &cb_;
|
||||
}
|
||||
|
||||
const_iterator
|
||||
end() const
|
||||
{
|
||||
return begin()+1;
|
||||
}
|
||||
};
|
||||
|
||||
template<class... Vn>
|
||||
cbuf_helper<sizeof...(Vn)>
|
||||
cbuf(Vn... vn)
|
||||
{
|
||||
return cbuf_helper<sizeof...(Vn)>(vn...);
|
||||
return {bytes.begin(), bytes.size()};
|
||||
}
|
||||
|
||||
template<std::size_t N>
|
||||
|
Reference in New Issue
Block a user