Unverified Commit 07b7be79 authored by davkor's avatar davkor

adds oss-fuzz setup.

parent 31c2a2c6
......@@ -20,6 +20,7 @@ option(PISTACHE_BUILD_TESTS "build tests alongside the project" OFF)
option(PISTACHE_ENABLE_NETWORK_TESTS "if tests are built, run ones needing network access" ON)
option(PISTACHE_USE_SSL "add support for SSL server" OFF)
option(PISTACHE_PIC "Enable pistache PIC" ON)
option(PISTACHE_BUILD_FUZZ "Build fuzzer for oss-fuzz" OFF)
# require fat LTO objects in static library
if(CMAKE_INTERPROCEDURAL_OPTIMIZATION OR CMAKE_CXX_FLAGS MATCHES "-flto" OR CMAKE_CXX_FLAGS MATCHES "-flto=thin")
......@@ -105,6 +106,10 @@ if (PISTACHE_BUILD_TESTS)
add_subdirectory(tests)
endif()
if (PISTACHE_BUILD_FUZZ)
add_subdirectory(tests/fuzzers)
endif()
# format target
add_custom_target(format
......
add_executable(fuzz_parser fuzz_parser.cpp)
target_link_libraries(fuzz_parser pistache_static)
set_target_properties(fuzz_parser PROPERTIES LINK_FLAGS $ENV{LIB_FUZZING_ENGINE})
#include <pistache/http.h>
using namespace Pistache;
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
std::string input(reinterpret_cast<const char*>(data), size);
// URI parsing
Http::Uri::Query query1;
query1.add(input, input);
// HTTP parsing
Pistache::Http::Header::CacheControl cc1;
try {
cc1.parse(input);
} catch(...) {}
Pistache::Http::Header::Accept a1;
try {
a1.parse(input);
} catch(...) {}
Pistache::Http::Header::Accept a2;
try {
a2.parse(input);
} catch (...) {}
Pistache::Http::Header::Authorization au;
try {
au.parse(input);
} catch(...) {}
Pistache::Http::Header::Expect e;
try {
e.parse(input);
} catch(...) {}
Pistache::Http::Header::Connection connection;
try {
connection.parse(input);
} catch(...) {}
Pistache::Http::Header::Date d;
try {
d.parse(input);
} catch(...) {}
Pistache::Http::Header::Host h;
try {
h.parse(input);
} catch(...) {}
Pistache::Http::Header::ContentEncoding ce;
try {
ce.parse(input);
} catch(...) {}
Pistache::Http::Header::ContentType ct;
try {
ct.parse(input);
} catch(...) {}
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment