diff --git a/fuzz/CMakeLists.txt b/fuzz/CMakeLists.txt index 2ab176666..0a1956072 100644 --- a/fuzz/CMakeLists.txt +++ b/fuzz/CMakeLists.txt @@ -14,6 +14,9 @@ if (ENABLE_FUZZING) + include(ProcessorCount) + ProcessorCount(nproc) + macro(add_fuzz_target binary) add_executable(${binary} ${binary}.cc $ $) target_link_libraries(${binary} Fuzzer osrm) @@ -23,7 +26,7 @@ if (ENABLE_FUZZING) DEPENDS ${binary} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -E make_directory "corpus/${binary}" - COMMAND ${binary} -jobs=1 -max_len=4096 "corpus/${binary}" + COMMAND ${binary} -jobs=${nproc} -workers=${nproc} -max_len=4096 "corpus/${binary}" COMMENT "Fuzzing ${binary}" VERBATIM) endmacro () @@ -33,7 +36,9 @@ if (ENABLE_FUZZING) "route_parameters" "table_parameters" "tile_parameters" - "trip_parameters") + "trip_parameters" + "url_parser" + "request_parser") foreach (target ${targets}) add_fuzz_target(${target}) diff --git a/fuzz/request_parser.cc b/fuzz/request_parser.cc new file mode 100644 index 000000000..e292ab27e --- /dev/null +++ b/fuzz/request_parser.cc @@ -0,0 +1,28 @@ +#include "server/request_parser.hpp" +#include "server/http/request.hpp" + +#include "util.hpp" + +#include +#include + +using osrm::server::RequestParser; +using osrm::server::http::request; + +extern "C" int LLVMFuzzerTestOneInput(const unsigned char *data, unsigned long size) +{ + std::string in(reinterpret_cast(data), size); + + auto first = begin(in); + auto last = end(in); + + RequestParser parser; + request req; + + // &(*it) is needed to go from iterator to underlying item to pointer to underlying item + parser.parse(req, &(*first), &(*last)); + + escape(&req); + + return 0; +} diff --git a/fuzz/url_parser.cc b/fuzz/url_parser.cc new file mode 100644 index 000000000..5a4b98ff0 --- /dev/null +++ b/fuzz/url_parser.cc @@ -0,0 +1,21 @@ +#include "server/api/url_parser.hpp" + +#include "util.hpp" + +#include +#include + +using osrm::server::api::parseURL; + +extern "C" int LLVMFuzzerTestOneInput(const unsigned char *data, unsigned long size) +{ + std::string in(reinterpret_cast(data), size); + + auto first = begin(in); + const auto last = end(in); + + const auto param = parseURL(first, last); + escape(¶m); + + return 0; +}