/src/boost/libs/beast/test/fuzz/websocket_server.cpp
Line | Count | Source |
1 | | // |
2 | | // Copyright (c) 2024 Mikhail Khachayants |
3 | | // |
4 | | // Distributed under the Boost Software License, Version 1.0. (See accompanying |
5 | | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
6 | | // |
7 | | |
8 | | #include <boost/beast/websocket.hpp> |
9 | | #include <boost/beast/_experimental/test/stream.hpp> |
10 | | |
11 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) |
12 | 8.31k | { |
13 | 8.31k | using namespace boost::beast; |
14 | | |
15 | 8.31k | error_code ec; |
16 | 8.31k | flat_buffer buffer; |
17 | 8.31k | net::io_context ioc; |
18 | 8.31k | test::stream remote{ioc}; |
19 | | |
20 | 8.31k | websocket::stream<test::stream> ws{ |
21 | 8.31k | ioc, string_view{reinterpret_cast<const char*>(data), size}}; |
22 | | |
23 | 8.31k | ws.set_option(websocket::stream_base::decorator( |
24 | 8.31k | [](websocket::response_type& res) |
25 | 8.31k | { |
26 | 4.77k | res.set(http::field::server, "websocket-server-sync"); |
27 | 4.77k | })); |
28 | | |
29 | 8.31k | websocket::permessage_deflate pd; |
30 | 8.31k | pd.server_enable = (size % 2) != 0; |
31 | 8.31k | pd.compLevel = static_cast<int>(size % 9); |
32 | 8.31k | ws.set_option(pd); |
33 | | |
34 | 8.31k | ws.next_layer().connect(remote); |
35 | 8.31k | ws.next_layer().close_remote(); |
36 | 8.31k | ws.accept(ec); |
37 | | |
38 | 8.31k | if(!ec) |
39 | 4.31k | { |
40 | 4.31k | ws.read(buffer, ec); |
41 | 4.31k | ws.text(ws.got_text()); |
42 | 4.31k | ws.write(buffer.data(), ec); |
43 | 4.31k | } |
44 | | |
45 | 8.31k | return 0; |
46 | 8.31k | } |