Skip to content

Commit

Permalink
Add fuzz testing drivers for url and request parser
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-j-h authored and TheMarex committed Aug 19, 2016
1 parent 06b74c1 commit 4b7ddb6
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
9 changes: 7 additions & 2 deletions fuzz/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

if (ENABLE_FUZZING)

include(ProcessorCount)
ProcessorCount(nproc)

macro(add_fuzz_target binary)
add_executable(${binary} ${binary}.cc $<TARGET_OBJECTS:UTIL> $<TARGET_OBJECTS:SERVER>)
target_link_libraries(${binary} Fuzzer osrm)
Expand All @@ -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 ()

Expand All @@ -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})
Expand Down
28 changes: 28 additions & 0 deletions fuzz/request_parser.cc
Original file line number Diff line number Diff line change
@@ -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 changes: 21 additions & 0 deletions fuzz/url_parser.cc
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 4b7ddb6

Please sign in to comment.