0
0
mirror of https://github.com/monero-project/kovri synced 2025-10-06 00:32:51 +02:00

kovri-util: add fuzz tests

This commit is contained in:
MoroccanMalinois
2017-05-07 02:09:25 +00:00
parent c209d470da
commit 08ff81240c
14 changed files with 820 additions and 2 deletions

View File

@@ -49,6 +49,7 @@ option(WITH_OPTIMIZE "Optimization flags" OFF)
option(WITH_STATIC "Static build" OFF)
option(WITH_SUPERCOP "Build Ed25519 using the ref10 implementation from SUPERCOP" ON) # Default ON unless we switch implementations
option(WITH_TESTS "Build unit tests" OFF)
option(WITH_FUZZ_TESTS "Build fuzz tests" OFF)
option(WITH_UPNP "Include support for UPnP client" OFF)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
@@ -269,6 +270,24 @@ if(WITH_UPNP)
endif()
endif()
if(WITH_FUZZ_TESTS)
if(NOT CLANG)
message(FATAL_ERROR "clang is required for fuzz tests. See building instructions.")
endif()
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS 5)
message(FATAL_ERROR "Clang version 5 or higher is required")
endif()
find_package(Fuzzer REQUIRED)
if(NOT Fuzzer_FOUND)
message(FATAL_ERROR "Could not find Fuzzer. See building instructions.")
else()
message(STATUS "Found Fuzzer: ${Fuzzer_INCLUDE_DIR}, ${Fuzzer_LIBRARIES}")
include_directories(${Fuzzer_INCLUDE_DIR})
add_definitions(-DWITH_FUZZ_TESTS)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize-coverage=trace-pc-guard -fsanitize=address")
endif()
# Doxygen support
if(WITH_DOXYGEN)
include(UseDoxygen)
@@ -301,6 +320,7 @@ message(STATUS " OPTIMIZATION : ${WITH_OPTIMIZE}")
message(STATUS " STATIC BUILD : ${WITH_STATIC}")
message(STATUS " SUPERCOP : ${WITH_SUPERCOP}")
message(STATUS " TESTS : ${WITH_TESTS}")
message(STATUS " FUZZ TESTS : ${WITH_FUZZ_TESTS}")
message(STATUS " UPnP : ${WITH_UPNP}")
message(STATUS "---------------------------------------")

View File

@@ -65,6 +65,7 @@ cmake-upnp = -D WITH_UPNP=ON
cmake-optimize = -D WITH_OPTIMIZE=ON
cmake-hardening = -D WITH_HARDENING=ON
cmake-tests = -D WITH_TESTS=ON
cmake-fuzz-tests = -D WITH_FUZZ_TESTS=ON
cmake-static = -D WITH_STATIC=ON
cmake-doxygen = -D WITH_DOXYGEN=ON
cmake-coverage = -D WITH_COVERAGE=ON
@@ -87,6 +88,7 @@ build = build/
build-cpp-netlib = deps/cpp-netlib/$(build)
build-cryptopp = deps/cryptopp/$(build)
build-doxygen = doc/Doxygen
build-fuzzer = contrib/Fuzzer/$(build)
# CMake builder macros
define CMAKE
@@ -106,6 +108,13 @@ define CMAKE_CRYPTOPP
$(call CMAKE,$(build-cryptopp),$(cmake-cryptopp))
endef
define CMAKE_FUZZER
@echo "=== Building fuzzer ==="
$(eval cmake-fuzzer = $(cmake-release) -DLLVM_USE_SANITIZER=Address -DLLVM_USE_SANITIZE_COVERAGE=YES \
-DCMAKE_CXX_FLAGS="-g -O2 -fno-omit-frame-pointer -std=c++11" $1)
$(call CMAKE,$(build-fuzzer),$(cmake-fuzzer))
endef
# Targets
all: dynamic
@@ -188,6 +197,11 @@ tests: deps
$(eval cmake-kovri += $(cmake-tests) $(cmake-benchmarks))
$(call CMAKE,$(build),$(cmake-kovri)) && $(MAKE)
fuzz-tests: deps
$(call CMAKE_FUZZER) && $(MAKE)
$(eval cmake-kovri += $(cmake-fuzz-tests) )
$(call CMAKE,$(build),$(cmake-kovri)) && $(MAKE)
doxygen:
$(eval cmake-kovri += $(cmake-disable-options) $(cmake-doxygen))
$(call CMAKE,$(build),$(cmake-kovri)) && $(MAKE)
@@ -197,7 +211,7 @@ help:
$(call CMAKE,$(build),$(cmake-kovri)) && $(MAKE)
clean:
$(eval remove-build = rm -fR $(build) $(build-cpp-netlib) $(build-cryptopp) $(build-doxygen))
$(eval remove-build = rm -fR $(build) $(build-cpp-netlib) $(build-cryptopp) $(build-doxygen) $(build-fuzzer))
@if [ "$$FORCE_CLEAN" = "yes" ]; then $(remove-build); \
else echo "CAUTION: This will remove the build directories for Kovri and all submodule dependencies, and remove all Doxygen output"; \
read -r -p "Is this what you wish to do? (y/N)?: " CONFIRM; \

70
cmake/FindFuzzer.cmake Normal file
View File

@@ -0,0 +1,70 @@
#
# Copyright (c) 2015-2017, The Kovri I2P Router Project
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are
# permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of
# conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list
# of conditions and the following disclaimer in the documentation and/or other
# materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be
# used to endorse or promote products derived from this software without specific
# prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
function(FindFuzzerLibrary)
find_library(Fuzzer_LIBRARIES
NAMES LLVMFuzzerNoMain
PATHS ${PROJECT_SOURCE_DIR}/contrib/Fuzzer/build /usr/lib /usr/local/lib
NO_DEFAULT_PATH)
endfunction(FindFuzzerLibrary)
function(BuildFuzzerLibrary)
message("Building libFuzzer.a ...")
AUX_SOURCE_DIRECTORY(${Fuzzer_INCLUDE_DIR} FUZZER_SRC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -O2 -fno-omit-frame-pointer -std=c++11")
add_library("Fuzzer" ${FUZZER_SRC})
install(
TARGETS "Fuzzer"
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_BINDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_BINDIR})
endfunction(BuildFuzzerLibrary)
if(Fuzzer_INCLUDE_DIR AND Fuzzer_LIBRARIES)
set(Fuzzer_FOUND TRUE)
else(Fuzzer_INCLUDE_DIR AND Fuzzer_LIBRARIES)
find_path(Fuzzer_INCLUDE_DIR
name FuzzerDefs.h
PATHS ${PROJECT_SOURCE_DIR}/contrib/Fuzzer /usr/include /usr/local/include
NO_DEFAULT_PATH)
FindFuzzerLibrary()
if(Fuzzer_INCLUDE_DIR AND Fuzzer_LIBRARIES)
set(Fuzzer_FOUND TRUE)
else(Fuzzer_INCLUDE_DIR AND Fuzzer_LIBRARIES)
set(Fuzzer_FOUND FALSE)
endif(Fuzzer_INCLUDE_DIR AND Fuzzer_LIBRARIES)
mark_as_advanced(Fuzzer_INCLUDE_DIR Fuzzer_LIBRARIES)
endif(Fuzzer_INCLUDE_DIR AND Fuzzer_LIBRARIES)

View File

@@ -7,8 +7,20 @@ set(UTIL_SRC
"benchmark.cc"
"main.cc")
if(WITH_FUZZ_TESTS)
include_directories("${Fuzzer_INCLUDE_DIR}")
list(APPEND UTIL_SRC
"../../tests/fuzz_tests/lease_set.cc"
"../../tests/fuzz_tests/routerinfo.cc"
"../../tests/fuzz_tests/su3.cc"
"fuzz.cc")
endif()
if(WITH_BINARY)
ConfigureBinary(${UTIL_NAME} "${UTIL_SRC}" ${UTIL_NAME})
if(WITH_FUZZ_TESTS)
target_link_libraries(${UTIL_NAME} ${Fuzzer_LIBRARIES})
endif()
endif()
# vim: noai:ts=2:sw=2

197
src/util/fuzz.cc Normal file
View File

@@ -0,0 +1,197 @@
/** //
* Copyright (c) 2015-2017, The Kovri I2P Router Project //
* //
* All rights reserved. //
* //
* Redistribution and use in source and binary forms, with or without modification, are //
* permitted provided that the following conditions are met: //
* //
* 1. Redistributions of source code must retain the above copyright notice, this list of //
* conditions and the following disclaimer. //
* //
* 2. Redistributions in binary form must reproduce the above copyright notice, this list //
* of conditions and the following disclaimer in the documentation and/or other //
* materials provided with the distribution. //
* //
* 3. Neither the name of the copyright holder nor the names of its contributors may be //
* used to endorse or promote products derived from this software without specific //
* prior written permission. //
* //
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY //
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF //
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL //
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, //
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, //
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS //
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, //
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF //
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. //
*/
#include "util/fuzz.h"
#include <FuzzerDefs.h>
#include <memory>
#include "core/util/log.h"
#include "tests/fuzz_tests/lease_set.h"
#include "tests/fuzz_tests/routerinfo.h"
#include "tests/fuzz_tests/su3.h"
#include "tests/fuzz_tests/target.h"
namespace bpo = boost::program_options;
// Helper for conversion from std::vector to (int, char**)
struct ArgvDeleter
{
explicit ArgvDeleter(std::size_t size) : m_Size(size)
{
}
void operator()(char** ptr)
{
for (std::size_t i(0); i < m_Size; i++)
delete[] ptr[i];
delete[] ptr;
}
std::size_t m_Size;
};
typedef std::unique_ptr<char* [], ArgvDeleter> UniqueCharArrayPtr;
UniqueCharArrayPtr VectorToArgcArgv(
const std::vector<std::string> args,
int* argc)
{
UniqueCharArrayPtr argv(new char*[args.size()], ArgvDeleter(args.size()));
for (std::size_t i(0); i < args.size(); i++)
{
argv.get()[i] = new char[args.at(i).size() + 1];
snprintf(argv.get()[i], args.at(i).size() + 1, "%s", args.at(i).c_str());
}
for (int i(0); i < *argc; i++)
LOG(info) << "i " << i << " " << argv.get()[i];
*argc = args.size();
return argv;
}
kovri::fuzz::FuzzTarget* CurrentTarget = nullptr;
// Fuzz callbacks
extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv)
{
if (!CurrentTarget)
return 0;
return CurrentTarget->Initialize(argc, argv);
}
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
return CurrentTarget->Impl(data, size);
}
// Fuzz command
FuzzCommand::FuzzCommand()
{
}
void FuzzCommand::PrintAvailableTargets() const
{
LOG(info) << "Available targets : ";
LOG(info) << "\tleaseset";
LOG(info) << "\trouterinfo";
LOG(info) << "\tsu3";
}
void FuzzCommand::PrintUsage(const std::string& name) const
{
LOG(info) << "Syntax: " << name;
LOG(info) << "\t--help";
LOG(info) << "\t--list";
LOG(info) << "\t--target=TARGET -merge=1 CORPUS_DIR RAW_CORPUS_DIR";
LOG(info) << "\t--target=TARGET <libfuzzer_options> CORPUS_DIR";
PrintAvailableTargets();
// Print libFuzzer options
LOG(info) << "LibFuzzer options:";
std::vector<std::string> fuzz_args;
fuzz_args.push_back(name);
fuzz_args.push_back("-help=1");
int argc = {};
UniqueCharArrayPtr argv = VectorToArgcArgv(fuzz_args, &argc);
char** argv_ptr = argv.get();
fuzzer::FuzzerDriver(&argc, &argv_ptr, LLVMFuzzerTestOneInput);
}
bool FuzzCommand::Impl(
const std::string& cmd_name,
const std::vector<std::string>& args)
{
std::string target;
bpo::options_description desc("Options");
desc.add_options()("list,l", "list available targets")(
"target,t", bpo::value<std::string>(&target), "fuzz target");
bpo::variables_map vm;
std::vector<std::string> fuzz_options;
try
{
bpo::parsed_options parsed = bpo::command_line_parser(args)
.options(desc)
.allow_unregistered()
.run();
fuzz_options =
bpo::collect_unrecognized(parsed.options, bpo::include_positional);
bpo::store(parsed, vm);
bpo::notify(vm);
}
catch (...)
{
kovri::core::Exception ex(GetName().c_str());
ex.Dispatch(__func__);
return false;
}
if (vm.count("list"))
{
PrintAvailableTargets();
return false;
}
// Handle target
if (target.empty())
{
LOG(error) << "Fuzz: Empty target !";
PrintUsage(cmd_name);
return false;
}
else if (target == "su3")
{
CurrentTarget = new kovri::fuzz::SU3();
}
else if (target == "routerinfo")
{
CurrentTarget = new kovri::fuzz::RouterInfo();
}
else if (target == "leaseset")
{
CurrentTarget = new kovri::fuzz::LeaseSet();
}
else
{
LOG(error) << "Fuzz: Invalid target " << target;
PrintUsage(cmd_name);
return false;
}
// Prepend with --target=target
fuzz_options.insert(fuzz_options.begin(), std::string("--target=") + target);
// Prepend with program name
fuzz_options.insert(fuzz_options.begin(), cmd_name);
// Transform fuzz_options to (argc,argv)
int argc = {};
UniqueCharArrayPtr argv = VectorToArgcArgv(fuzz_options, &argc);
char** argv_ptr = argv.get();
// Start fuzzing
return fuzzer::FuzzerDriver(&argc, &argv_ptr, LLVMFuzzerTestOneInput);
}

60
src/util/fuzz.h Normal file
View File

@@ -0,0 +1,60 @@
/** //
* Copyright (c) 2015-2017, The Kovri I2P Router Project //
* //
* All rights reserved. //
* //
* Redistribution and use in source and binary forms, with or without modification, are //
* permitted provided that the following conditions are met: //
* //
* 1. Redistributions of source code must retain the above copyright notice, this list of //
* conditions and the following disclaimer. //
* //
* 2. Redistributions in binary form must reproduce the above copyright notice, this list //
* of conditions and the following disclaimer in the documentation and/or other //
* materials provided with the distribution. //
* //
* 3. Neither the name of the copyright holder nor the names of its contributors may be //
* used to endorse or promote products derived from this software without specific //
* prior written permission. //
* //
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY //
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF //
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL //
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, //
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, //
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS //
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, //
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF //
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. //
*/
#ifndef SRC_UTIL_FUZZ_H_
#define SRC_UTIL_FUZZ_H_
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include "util/command.h"
/**
* @class FuzzCommand
* @brief class for command fuzz
*/
class FuzzCommand : public Command
{
public:
FuzzCommand();
void PrintUsage(const std::string& cmd_name) const;
bool Impl(const std::string& path, const std::vector<std::string>& args);
std::string GetName(void) const
{
return "fuzz";
}
private:
void PrintAvailableTargets() const;
};
#endif // SRC_UTIL_FUZZ_H_

View File

@@ -32,10 +32,13 @@
#include "core/util/exception.h"
#include "core/util/log.h"
#include "util/base.h"
#include "util/benchmark.h"
#include "util/command.h"
#ifdef WITH_FUZZ_TESTS
#include "util/fuzz.h"
#endif // WITH_FUZZ_TESTS
#include "util/routerinfo.h"
#include "util/su3file.h"
#include "util/benchmark.h"
namespace bpo = boost::program_options;
typedef std::map<std::string, Command*> ListCommands;
@@ -66,6 +69,11 @@ int main(int argc, const char* argv[])
list_cmd[routerinfo_cmd.GetName()] = &routerinfo_cmd;
list_cmd[benchmark_cmd.GetName()] = &benchmark_cmd;
#ifdef WITH_FUZZ_TESTS
FuzzCommand fuzz_cmd;
list_cmd[fuzz_cmd.GetName()] = &fuzz_cmd;
#endif // WITH_FUZZ_TESTS
bpo::options_description general_desc("General options");
// See src/app/config.cc for log options
general_desc.add_options()("help,h", "produce this help message")(

View File

@@ -0,0 +1,63 @@
/** //
* Copyright (c) 2015-2017, The Kovri I2P Router Project //
* //
* All rights reserved. //
* //
* Redistribution and use in source and binary forms, with or without modification, are //
* permitted provided that the following conditions are met: //
* //
* 1. Redistributions of source code must retain the above copyright notice, this list of //
* conditions and the following disclaimer. //
* //
* 2. Redistributions in binary form must reproduce the above copyright notice, this list //
* of conditions and the following disclaimer in the documentation and/or other //
* materials provided with the distribution. //
* //
* 3. Neither the name of the copyright holder nor the names of its contributors may be //
* used to endorse or promote products derived from this software without specific //
* prior written permission. //
* //
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY //
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF //
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL //
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, //
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, //
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS //
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, //
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF //
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. //
*/
#include "tests/fuzz_tests/lease_set.h"
#include "core/util/log.h"
namespace kovri
{
namespace fuzz
{
int LeaseSet::Initialize(int*, char***)
{
// nothing to do
return 0;
}
int LeaseSet::Impl(const uint8_t* data, size_t size)
{
try
{
if (!m_LeaseSet)
m_LeaseSet.reset(new kovri::core::LeaseSet(data, size));
else
m_LeaseSet->Update(data, size);
}
catch (...)
{
kovri::core::Exception ex;
ex.Dispatch(__func__);
return 0;
}
return 0;
}
} // namespace fuzz
} // namespace kovri

View File

@@ -0,0 +1,60 @@
/** //
* Copyright (c) 2015-2017, The Kovri I2P Router Project //
* //
* All rights reserved. //
* //
* Redistribution and use in source and binary forms, with or without modification, are //
* permitted provided that the following conditions are met: //
* //
* 1. Redistributions of source code must retain the above copyright notice, this list of //
* conditions and the following disclaimer. //
* //
* 2. Redistributions in binary form must reproduce the above copyright notice, this list //
* of conditions and the following disclaimer in the documentation and/or other //
* materials provided with the distribution. //
* //
* 3. Neither the name of the copyright holder nor the names of its contributors may be //
* used to endorse or promote products derived from this software without specific //
* prior written permission. //
* //
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY //
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF //
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL //
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, //
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, //
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS //
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, //
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF //
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. //
*/
#ifndef TESTS_FUZZ_TESTS_LEASE_SET_H_
#define TESTS_FUZZ_TESTS_LEASE_SET_H_
#include <memory>
#include "core/router/lease_set.h"
#include "tests/fuzz_tests/target.h"
namespace kovri
{
namespace fuzz
{
/**
* @class RouterInfo
* @brief Specialization of FuzzTarget for routerinfo
*/
class LeaseSet : public FuzzTarget
{
public:
virtual int Initialize(int* argc, char*** argv);
virtual int Impl(const uint8_t* data, size_t size);
private:
std::unique_ptr<kovri::core::LeaseSet> m_LeaseSet;
};
} // namespace fuzz
} // namespace kovri
#endif // TESTS_FUZZ_TESTS_LEASE_SET_H_

View File

@@ -0,0 +1,62 @@
/** //
* Copyright (c) 2015-2017, The Kovri I2P Router Project //
* //
* All rights reserved. //
* //
* Redistribution and use in source and binary forms, with or without modification, are //
* permitted provided that the following conditions are met: //
* //
* 1. Redistributions of source code must retain the above copyright notice, this list of //
* conditions and the following disclaimer. //
* //
* 2. Redistributions in binary form must reproduce the above copyright notice, this list //
* of conditions and the following disclaimer in the documentation and/or other //
* materials provided with the distribution. //
* //
* 3. Neither the name of the copyright holder nor the names of its contributors may be //
* used to endorse or promote products derived from this software without specific //
* prior written permission. //
* //
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY //
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF //
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL //
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, //
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, //
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS //
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, //
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF //
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. //
* //
*/
#include "tests/fuzz_tests/routerinfo.h"
#include "core/router/info.h"
namespace kovri
{
namespace fuzz
{
int RouterInfo::Initialize(int*, char***)
{
// nothing to do
return 0;
}
int RouterInfo::Impl(const uint8_t* data, size_t size)
{
try
{
kovri::core::RouterInfo ri(data, size);
ri.GetDescription();
}
catch (...)
{
kovri::core::Exception ex;
ex.Dispatch(__func__);
return 0;
}
return 0;
}
} // namespace fuzz
} // namespace kovri

View File

@@ -0,0 +1,55 @@
/** //
* Copyright (c) 2015-2017, The Kovri I2P Router Project //
* //
* All rights reserved. //
* //
* Redistribution and use in source and binary forms, with or without modification, are //
* permitted provided that the following conditions are met: //
* //
* 1. Redistributions of source code must retain the above copyright notice, this list of //
* conditions and the following disclaimer. //
* //
* 2. Redistributions in binary form must reproduce the above copyright notice, this list //
* of conditions and the following disclaimer in the documentation and/or other //
* materials provided with the distribution. //
* //
* 3. Neither the name of the copyright holder nor the names of its contributors may be //
* used to endorse or promote products derived from this software without specific //
* prior written permission. //
* //
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY //
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF //
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL //
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, //
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, //
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS //
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, //
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF //
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. //
*/
#ifndef TESTS_FUZZ_TESTS_ROUTERINFO_H_
#define TESTS_FUZZ_TESTS_ROUTERINFO_H_
#include "tests/fuzz_tests/target.h"
namespace kovri
{
namespace fuzz
{
/**
* @class RouterInfo
* @brief Specialization of FuzzTarget for routerinfo
*/
class RouterInfo : public FuzzTarget
{
public:
virtual int Initialize(int* argc, char*** argv);
virtual int Impl(const uint8_t* data, size_t size);
};
} // namespace fuzz
} // namespace kovri
#endif // TESTS_FUZZ_TESTS_ROUTERINFO_H_

70
tests/fuzz_tests/su3.cc Normal file
View File

@@ -0,0 +1,70 @@
/** //
* Copyright (c) 2015-2017, The Kovri I2P Router Project //
* //
* All rights reserved. //
* //
* Redistribution and use in source and binary forms, with or without modification, are //
* permitted provided that the following conditions are met: //
* //
* 1. Redistributions of source code must retain the above copyright notice, this list of //
* conditions and the following disclaimer. //
* //
* 2. Redistributions in binary form must reproduce the above copyright notice, this list //
* of conditions and the following disclaimer in the documentation and/or other //
* materials provided with the distribution. //
* //
* 3. Neither the name of the copyright holder nor the names of its contributors may be //
* used to endorse or promote products derived from this software without specific //
* prior written permission. //
* //
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY //
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF //
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL //
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, //
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, //
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS //
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, //
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF //
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. //
* //
*/
#include "tests/fuzz_tests/su3.h"
#include <stddef.h>
#include <stdint.h>
#include "client/reseed.h"
namespace kovri
{
namespace fuzz
{
int SU3::Initialize(int*, char***)
{
boost::filesystem::path cert_dir_path = kovri::core::GetSU3CertsPath();
if (!kovri::client::Reseed::ProcessCerts(&m_Keys, cert_dir_path))
{
LOG(error) << "su3file: Failed to get trusted certificates !";
return 1;
}
return 0;
}
int SU3::Impl(const uint8_t* data, size_t size)
{
try
{
std::string su3_str(data, data + size);
kovri::client::SU3 su3(su3_str, m_Keys);
su3.SU3Impl();
}
catch (...)
{
kovri::core::Exception ex;
ex.Dispatch(__func__);
return 0;
}
return 0;
}
} // namespace fuzz
} // namespace kovri

61
tests/fuzz_tests/su3.h Normal file
View File

@@ -0,0 +1,61 @@
/** //
* Copyright (c) 2015-2017, The Kovri I2P Router Project //
* //
* All rights reserved. //
* //
* Redistribution and use in source and binary forms, with or without modification, are //
* permitted provided that the following conditions are met: //
* //
* 1. Redistributions of source code must retain the above copyright notice, this list of //
* conditions and the following disclaimer. //
* //
* 2. Redistributions in binary form must reproduce the above copyright notice, this list //
* of conditions and the following disclaimer in the documentation and/or other //
* materials provided with the distribution. //
* //
* 3. Neither the name of the copyright holder nor the names of its contributors may be //
* used to endorse or promote products derived from this software without specific //
* prior written permission. //
* //
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY //
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF //
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL //
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, //
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, //
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS //
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, //
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF //
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. //
*/
#ifndef TESTS_FUZZ_TESTS_SU3_H_
#define TESTS_FUZZ_TESTS_SU3_H_
#include <core/crypto/util/x509.h>
#include <map>
#include <string>
#include "tests/fuzz_tests/target.h"
namespace kovri
{
namespace fuzz
{
/**
* @class SU3
* @brief Specialization of FuzzTarget for SU3
*/
class SU3 : public FuzzTarget
{
public:
virtual int Initialize(int* argc, char*** argv);
virtual int Impl(const uint8_t* data, size_t size);
private:
std::map<std::string, kovri::core::PublicKey> m_Keys;
};
} // namespace fuzz
} // namespace kovri
#endif // TESTS_FUZZ_TESTS_SU3_H_

66
tests/fuzz_tests/target.h Normal file
View File

@@ -0,0 +1,66 @@
/** //
* Copyright (c) 2015-2017, The Kovri I2P Router Project //
* //
* All rights reserved. //
* //
* Redistribution and use in source and binary forms, with or without modification, are //
* permitted provided that the following conditions are met: //
* //
* 1. Redistributions of source code must retain the above copyright notice, this list of //
* conditions and the following disclaimer. //
* //
* 2. Redistributions in binary form must reproduce the above copyright notice, this list //
* of conditions and the following disclaimer in the documentation and/or other //
* materials provided with the distribution. //
* //
* 3. Neither the name of the copyright holder nor the names of its contributors may be //
* used to endorse or promote products derived from this software without specific //
* prior written permission. //
* //
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY //
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF //
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL //
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, //
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, //
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS //
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, //
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF //
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. //
*/
#ifndef TESTS_FUZZ_TESTS_TARGET_H_
#define TESTS_FUZZ_TESTS_TARGET_H_
#include <cstddef>
#include <cstdint>
namespace kovri
{
namespace fuzz
{
/**
* @class FuzzTarget
* @brief Base class for all fuzz targets
* @details All fuzz targets must inherit this class
*/
class FuzzTarget
{
public:
/// @brief Initialization of the target
/// @param argc : number of arguments
/// @param argv : array of string arguments
/// @return 0 on success, 1 otherwise
virtual int Initialize(int* argc, char*** argv) = 0;
/// @brief Implementation of the target
/// @param data Input randomized buffer
/// @param size Size of the input buffer
/// @return 0 on success, 1 otherwise
virtual int Impl(const uint8_t* data, size_t size) = 0;
};
} // namespace fuzz
} // namespace kovri
#endif // TESTS_FUZZ_TESTS_TARGET_H_