-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
boost: add fuzzers for beast library
boost_beast_request_fuzzer for fuzzing HTTP requests parser boost_beast_response_fuzzer for fuzzing HTTP responses parser boost_beast_ws_server_fuzzer for fuzzing WebSocket server
- Loading branch information
Showing
4 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <boost/beast.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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <boost/beast.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 size, 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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2024 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <boost/beast.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"); | ||
})); | ||
|
||
ws.set_option(websocket::permessage_deflate{ | ||
.server_enable = (size % 2) != 0, | ||
.compLevel = static_cast<int>(size % 9), | ||
}); | ||
|
||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters