Made use of libfuzzer
This commit is contained in:
parent
8e82428740
commit
f6df4cde4e
9 changed files with 107 additions and 13 deletions
|
|
@ -4,6 +4,7 @@ project (Simple-Web-Server)
|
||||||
|
|
||||||
option(USE_STANDALONE_ASIO "set ON to use standalone Asio instead of Boost.Asio" OFF)
|
option(USE_STANDALONE_ASIO "set ON to use standalone Asio instead of Boost.Asio" OFF)
|
||||||
option(BUILD_TESTING "set ON to build library tests" OFF)
|
option(BUILD_TESTING "set ON to build library tests" OFF)
|
||||||
|
option(BUILD_FUZZING "set ON to build library fuzzers" OFF)
|
||||||
option(USE_OPENSSL "set OFF to build without OpenSSL" ON)
|
option(USE_OPENSSL "set OFF to build without OpenSSL" ON)
|
||||||
|
|
||||||
add_library(simple-web-server INTERFACE)
|
add_library(simple-web-server INTERFACE)
|
||||||
|
|
@ -79,7 +80,9 @@ if(CMAKE_SOURCE_DIR STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||||
install(FILES asio_compatibility.hpp server_http.hpp client_http.hpp server_https.hpp client_https.hpp crypto.hpp utility.hpp status_code.hpp mutex.hpp DESTINATION include/simple-web-server)
|
install(FILES asio_compatibility.hpp server_http.hpp client_http.hpp server_https.hpp client_https.hpp crypto.hpp utility.hpp status_code.hpp mutex.hpp DESTINATION include/simple-web-server)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(BUILD_TESTING)
|
if(BUILD_TESTING OR BUILD_FUZZING)
|
||||||
enable_testing()
|
if(BUILD_TESTING)
|
||||||
|
enable_testing()
|
||||||
|
endif()
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
||||||
|
|
@ -4,21 +4,57 @@ if(NOT MSVC)
|
||||||
add_compile_options(-Wno-thread-safety)
|
add_compile_options(-Wno-thread-safety)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_executable(io_test io_test.cpp)
|
if(BUILD_TESTING)
|
||||||
target_link_libraries(io_test simple-web-server)
|
add_executable(io_test io_test.cpp)
|
||||||
add_test(NAME io_test COMMAND io_test)
|
target_link_libraries(io_test simple-web-server)
|
||||||
|
add_test(NAME io_test COMMAND io_test)
|
||||||
add_executable(parse_test parse_test.cpp)
|
|
||||||
target_link_libraries(parse_test simple-web-server)
|
add_executable(parse_test parse_test.cpp)
|
||||||
add_test(NAME parse_test COMMAND parse_test)
|
target_link_libraries(parse_test simple-web-server)
|
||||||
|
add_test(NAME parse_test COMMAND parse_test)
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(OPENSSL_FOUND)
|
if(OPENSSL_FOUND AND BUILD_TESTING)
|
||||||
add_executable(crypto_test crypto_test.cpp)
|
add_executable(crypto_test crypto_test.cpp)
|
||||||
target_link_libraries(crypto_test simple-web-server)
|
target_link_libraries(crypto_test simple-web-server)
|
||||||
add_test(NAME crypto_test COMMAND crypto_test)
|
add_test(NAME crypto_test COMMAND crypto_test)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_executable(status_code_test status_code_test.cpp)
|
if(BUILD_TESTING)
|
||||||
target_link_libraries(status_code_test simple-web-server)
|
add_executable(status_code_test status_code_test.cpp)
|
||||||
add_test(NAME status_code_test COMMAND status_code_test)
|
target_link_libraries(status_code_test simple-web-server)
|
||||||
|
add_test(NAME status_code_test COMMAND status_code_test)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(BUILD_FUZZING)
|
||||||
|
add_executable(percent_decode fuzzers/percent_decode.cpp)
|
||||||
|
target_compile_options(percent_decode PRIVATE -fsanitize=address,fuzzer)
|
||||||
|
target_link_options(percent_decode PRIVATE -fsanitize=address,fuzzer)
|
||||||
|
target_link_libraries(percent_decode simple-web-server)
|
||||||
|
|
||||||
|
add_executable(query_string_parse fuzzers/query_string_parse.cpp)
|
||||||
|
target_compile_options(query_string_parse PRIVATE -fsanitize=address,fuzzer)
|
||||||
|
target_link_options(query_string_parse PRIVATE -fsanitize=address,fuzzer)
|
||||||
|
target_link_libraries(query_string_parse simple-web-server)
|
||||||
|
|
||||||
|
add_executable(http_header_parse fuzzers/http_header_parse.cpp)
|
||||||
|
target_compile_options(http_header_parse PRIVATE -fsanitize=address,fuzzer)
|
||||||
|
target_link_options(http_header_parse PRIVATE -fsanitize=address,fuzzer)
|
||||||
|
target_link_libraries(http_header_parse simple-web-server)
|
||||||
|
|
||||||
|
add_executable(http_header_field_value_semicolon_separated_attributes_parse fuzzers/http_header_field_value_semicolon_separated_attributes_parse.cpp)
|
||||||
|
target_compile_options(http_header_field_value_semicolon_separated_attributes_parse PRIVATE -fsanitize=address,fuzzer)
|
||||||
|
target_link_options(http_header_field_value_semicolon_separated_attributes_parse PRIVATE -fsanitize=address,fuzzer)
|
||||||
|
target_link_libraries(http_header_field_value_semicolon_separated_attributes_parse simple-web-server)
|
||||||
|
|
||||||
|
add_executable(request_message_parse fuzzers/request_message_parse.cpp)
|
||||||
|
target_compile_options(request_message_parse PRIVATE -fsanitize=address,fuzzer)
|
||||||
|
target_link_options(request_message_parse PRIVATE -fsanitize=address,fuzzer)
|
||||||
|
target_link_libraries(request_message_parse simple-web-server)
|
||||||
|
|
||||||
|
add_executable(response_message_parse fuzzers/response_message_parse.cpp)
|
||||||
|
target_compile_options(response_message_parse PRIVATE -fsanitize=address,fuzzer)
|
||||||
|
target_link_options(response_message_parse PRIVATE -fsanitize=address,fuzzer)
|
||||||
|
target_link_libraries(response_message_parse simple-web-server)
|
||||||
|
endif()
|
||||||
6
tests/fuzzers/README.md
Normal file
6
tests/fuzzers/README.md
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
Prior to running the fuzzers, build and prepare for instance as follows:
|
||||||
|
```sh
|
||||||
|
CXX=clang++ cmake -DBUILD_FUZZING=1 ..
|
||||||
|
make
|
||||||
|
export LSAN_OPTIONS=detect_leaks=0
|
||||||
|
```
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
#include "utility.hpp"
|
||||||
|
|
||||||
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||||
|
SimpleWeb::HttpHeader::FieldValue::SemicolonSeparatedAttributes::parse(std::string(reinterpret_cast<const char *>(data), size));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
9
tests/fuzzers/http_header_parse.cpp
Normal file
9
tests/fuzzers/http_header_parse.cpp
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
#include "utility.hpp"
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << std::string(reinterpret_cast<const char *>(data), size);
|
||||||
|
SimpleWeb::HttpHeader::parse(ss);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
6
tests/fuzzers/percent_decode.cpp
Normal file
6
tests/fuzzers/percent_decode.cpp
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#include "utility.hpp"
|
||||||
|
|
||||||
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||||
|
SimpleWeb::Percent::decode(std::string(reinterpret_cast<const char *>(data), size));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
6
tests/fuzzers/query_string_parse.cpp
Normal file
6
tests/fuzzers/query_string_parse.cpp
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#include "utility.hpp"
|
||||||
|
|
||||||
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||||
|
SimpleWeb::QueryString::parse(std::string(reinterpret_cast<const char *>(data), size));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
11
tests/fuzzers/request_message_parse.cpp
Normal file
11
tests/fuzzers/request_message_parse.cpp
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
#include "utility.hpp"
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << std::string(reinterpret_cast<const char *>(data), size);
|
||||||
|
std::string method, path, query_string, version;
|
||||||
|
SimpleWeb::CaseInsensitiveMultimap header;
|
||||||
|
SimpleWeb::RequestMessage::parse(ss, method, path, query_string, version, header);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
11
tests/fuzzers/response_message_parse.cpp
Normal file
11
tests/fuzzers/response_message_parse.cpp
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
#include "utility.hpp"
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << std::string(reinterpret_cast<const char *>(data), size);
|
||||||
|
std::string version, status_code;
|
||||||
|
SimpleWeb::CaseInsensitiveMultimap header;
|
||||||
|
SimpleWeb::ResponseMessage::parse(ss, version, status_code, header);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue