Add fuzz testing drivers for url and request parser

This commit is contained in:
Daniel J. Hofmann 2016-04-13 10:50:43 +02:00 committed by Patrick Niklaus
parent 06b74c1f08
commit 4b7ddb6826
No known key found for this signature in database
GPG Key ID: E426891B5F978B1B
3 changed files with 56 additions and 2 deletions

View File

@ -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
View 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
View 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(&param);
return 0;
}