diff --git a/CHANGELOG.md b/CHANGELOG.md index 8ff5f8a9..3778bbd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ Version 261: * Deduplicate `websocket::read_size_hint` definition +* Fix UB in websocket read tests -------------------------------------------------------------------------------- diff --git a/test/beast/websocket/read2.cpp b/test/beast/websocket/read2.cpp index 0b1bb230..0f211fcf 100644 --- a/test/beast/websocket/read2.cpp +++ b/test/beast/websocket/read2.cpp @@ -133,7 +133,7 @@ public: [&](ws_type_t& 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& 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& 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& 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& 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); }); diff --git a/test/beast/websocket/test.hpp b/test/beast/websocket/test.hpp index 0ab27c1b..b4c90d2b 100644 --- a/test/beast/websocket/test.hpp +++ b/test/beast/websocket/test.hpp @@ -12,7 +12,6 @@ #include #include -#include #include #include #include @@ -22,9 +21,7 @@ #include #include #include -#include #include -#include #include #include #include @@ -377,42 +374,9 @@ public: //-------------------------------------------------------------------------- - template - class cbuf_helper + net::const_buffer cbuf(std::initializer_list bytes) { - std::array v_; - net::const_buffer cb_; - - public: - using value_type = decltype(cb_); - using const_iterator = value_type const*; - - template - explicit - cbuf_helper(Vn... vn) - : v_({{ static_cast(vn)... }}) - , cb_(v_.data(), v_.size()) - { - } - - const_iterator - begin() const - { - return &cb_; - } - - const_iterator - end() const - { - return begin()+1; - } - }; - - template - cbuf_helper - cbuf(Vn... vn) - { - return cbuf_helper(vn...); + return {bytes.begin(), bytes.size()}; } template