Add fuzz testing drivers for url and request parser
This commit is contained in:
parent
06b74c1f08
commit
4b7ddb6826
@ -14,6 +14,9 @@
|
|||||||
|
|
||||||
if (ENABLE_FUZZING)
|
if (ENABLE_FUZZING)
|
||||||
|
|
||||||
|
include(ProcessorCount)
|
||||||
|
ProcessorCount(nproc)
|
||||||
|
|
||||||
macro(add_fuzz_target binary)
|
macro(add_fuzz_target binary)
|
||||||
add_executable(${binary} ${binary}.cc $<TARGET_OBJECTS:UTIL> $<TARGET_OBJECTS:SERVER>)
|
add_executable(${binary} ${binary}.cc $<TARGET_OBJECTS:UTIL> $<TARGET_OBJECTS:SERVER>)
|
||||||
target_link_libraries(${binary} Fuzzer osrm)
|
target_link_libraries(${binary} Fuzzer osrm)
|
||||||
@ -23,7 +26,7 @@ if (ENABLE_FUZZING)
|
|||||||
DEPENDS ${binary}
|
DEPENDS ${binary}
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
COMMAND ${CMAKE_COMMAND} -E make_directory "corpus/${binary}"
|
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)
|
COMMENT "Fuzzing ${binary}" VERBATIM)
|
||||||
endmacro ()
|
endmacro ()
|
||||||
|
|
||||||
@ -33,7 +36,9 @@ if (ENABLE_FUZZING)
|
|||||||
"route_parameters"
|
"route_parameters"
|
||||||
"table_parameters"
|
"table_parameters"
|
||||||
"tile_parameters"
|
"tile_parameters"
|
||||||
"trip_parameters")
|
"trip_parameters"
|
||||||
|
"url_parser"
|
||||||
|
"request_parser")
|
||||||
|
|
||||||
foreach (target ${targets})
|
foreach (target ${targets})
|
||||||
add_fuzz_target(${target})
|
add_fuzz_target(${target})
|
||||||
|
28
fuzz/request_parser.cc
Normal file
28
fuzz/request_parser.cc
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
#include "server/request_parser.hpp"
|
||||||
|
#include "server/http/request.hpp"
|
||||||
|
|
||||||
|
#include "util.hpp"
|
||||||
|
|
||||||
|
#include <iterator>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
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<const char *>(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;
|
||||||
|
}
|
21
fuzz/url_parser.cc
Normal file
21
fuzz/url_parser.cc
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#include "server/api/url_parser.hpp"
|
||||||
|
|
||||||
|
#include "util.hpp"
|
||||||
|
|
||||||
|
#include <iterator>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
using osrm::server::api::parseURL;
|
||||||
|
|
||||||
|
extern "C" int LLVMFuzzerTestOneInput(const unsigned char *data, unsigned long size)
|
||||||
|
{
|
||||||
|
std::string in(reinterpret_cast<const char *>(data), size);
|
||||||
|
|
||||||
|
auto first = begin(in);
|
||||||
|
const auto last = end(in);
|
||||||
|
|
||||||
|
const auto param = parseURL(first, last);
|
||||||
|
escape(¶m);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user