mirror of
https://github.com/boostorg/beast.git
synced 2025-07-29 20:37:31 +02:00
Add fuzzing targets
This commit is contained in:
committed by
Mohammad Nejati
parent
e7f49190ef
commit
1b874927c1
25
test/fuzz/http_request.cpp
Normal file
25
test/fuzz/http_request.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
//
|
||||
// Copyright (c) 2024 Mikhail Khachayants
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include <boost/beast/http.hpp>
|
||||
#include <boost/beast/_experimental/test/stream.hpp>
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
using namespace boost::beast;
|
||||
|
||||
error_code ec;
|
||||
flat_buffer buffer;
|
||||
net::io_context ioc;
|
||||
test::stream stream{ioc, {reinterpret_cast<const char*>(data), size}};
|
||||
stream.close_remote();
|
||||
|
||||
http::request_parser<http::dynamic_body> parser;
|
||||
http::read(stream, buffer, parser, ec);
|
||||
|
||||
return 0;
|
||||
}
|
33
test/fuzz/http_response.cpp
Normal file
33
test/fuzz/http_response.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
//
|
||||
// Copyright (c) 2024 Mikhail Khachayants
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include <boost/beast/http.hpp>
|
||||
#include <boost/beast/_experimental/test/stream.hpp>
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
using namespace boost::beast;
|
||||
|
||||
error_code ec;
|
||||
flat_buffer buffer;
|
||||
net::io_context ioc;
|
||||
test::stream stream{ioc, {reinterpret_cast<const char*>(data), size}};
|
||||
stream.close_remote();
|
||||
|
||||
http::chunk_extensions ce;
|
||||
http::response_parser<http::dynamic_body> parser;
|
||||
|
||||
auto chunk_header_cb = [&ce](std::uint64_t, string_view extensions, error_code& ev)
|
||||
{
|
||||
ce.parse(extensions, ev);
|
||||
};
|
||||
|
||||
parser.on_chunk_header(chunk_header_cb);
|
||||
http::read(stream, buffer, parser, ec);
|
||||
|
||||
return 0;
|
||||
}
|
BIN
test/fuzz/seeds.tar
Normal file
BIN
test/fuzz/seeds.tar
Normal file
Binary file not shown.
46
test/fuzz/websocket_server.cpp
Normal file
46
test/fuzz/websocket_server.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
//
|
||||
// Copyright (c) 2024 Mikhail Khachayants
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include <boost/beast/websocket.hpp>
|
||||
#include <boost/beast/_experimental/test/stream.hpp>
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
|
||||
{
|
||||
using namespace boost::beast;
|
||||
|
||||
error_code ec;
|
||||
flat_buffer buffer;
|
||||
net::io_context ioc;
|
||||
test::stream remote{ioc};
|
||||
|
||||
websocket::stream<test::stream> ws{
|
||||
ioc, string_view{reinterpret_cast<const char*>(data), size}};
|
||||
|
||||
ws.set_option(websocket::stream_base::decorator(
|
||||
[](websocket::response_type& res)
|
||||
{
|
||||
res.set(http::field::server, "websocket-server-sync");
|
||||
}));
|
||||
|
||||
websocket::permessage_deflate pd;
|
||||
pd.server_enable = (size % 2) != 0;
|
||||
pd.compLevel = static_cast<int>(size % 9);
|
||||
ws.set_option(pd);
|
||||
|
||||
ws.next_layer().connect(remote);
|
||||
ws.next_layer().close_remote();
|
||||
ws.accept(ec);
|
||||
|
||||
if(!ec)
|
||||
{
|
||||
ws.read(buffer, ec);
|
||||
ws.text(ws.got_text());
|
||||
ws.write(buffer.data(), ec);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user