Skip to content

Commit

Permalink
Add fuzz testing drivers for json escaping and uri decoding
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 4b7ddb6 commit cdf6bab
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 3 deletions.
17 changes: 14 additions & 3 deletions fuzz/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ if (ENABLE_FUZZING)
COMMENT "Fuzzing ${binary}" VERBATIM)
endmacro ()

set(targets

set(ServerTargets
"match_parameters"
"nearest_parameters"
"route_parameters"
Expand All @@ -40,8 +41,18 @@ if (ENABLE_FUZZING)
"url_parser"
"request_parser")

foreach (target ${targets})
add_fuzz_target(${target})
foreach (target ${ServerTargets})
add_fuzz_target(${target})
endforeach ()


set(UtilTargets
"escape_json"
"uri_decode")

foreach (target ${UtilTargets})
add_fuzz_target(${target})
endforeach ()


endif ()
18 changes: 18 additions & 0 deletions fuzz/escape_json.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "util/string_util.hpp"

#include "util.hpp"

#include <iterator>
#include <string>

using osrm::util::escape_JSON;

extern "C" int LLVMFuzzerTestOneInput(const unsigned char *data, unsigned long size)
{
const std::string in(reinterpret_cast<const char *>(data), size);

const auto escaped = escape_JSON(in);
escape(escaped.data());

return 0;
}
21 changes: 21 additions & 0 deletions fuzz/uri_decode.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "server/api/url_parser.hpp"
#include "util/string_util.hpp"

#include "util.hpp"

#include <iterator>
#include <string>

using osrm::util::URIDecode;

extern "C" int LLVMFuzzerTestOneInput(const unsigned char *data, unsigned long size)
{
const std::string in(reinterpret_cast<const char *>(data), size);
std::string out;

(void)URIDecode(in, out);

escape(out.data());

return 0;
}

0 comments on commit cdf6bab

Please sign in to comment.