From 28cd5d7ea2ebcc2bc178092a5d3732ab54743dcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Tue, 31 Mar 2020 09:33:58 +0200 Subject: [PATCH] fixed OSS-Fuzz builds and added CMake targets (#2577) * fixed compilation of OSS-Fuzz clients * added preliminary CMake target for fuzz-client - also added *_sanitized targets of dependencies (only available with Clang) * added oss-fuzz build to Travis CI --- .travis.yml | 2 ++ CMakeLists.txt | 1 + externals/simplecpp/CMakeLists.txt | 4 ++++ externals/tinyxml/CMakeLists.txt | 4 ++++ lib/CMakeLists.txt | 5 ++++- oss-fuzz/CMakeLists.txt | 13 +++++++++++++ oss-fuzz/main.cpp | 17 ++++++++++++++--- 7 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 oss-fuzz/CMakeLists.txt diff --git a/.travis.yml b/.travis.yml index 913ad28e4..03bf3bad5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -164,6 +164,8 @@ matrix: - ./testrunner TestSymbolDatabase # check .json files - find . -name '*.json' -not -path '*/\.*' | xargs jsonlint -s +# build OSS-Fuzz clients + - make -j2 CXXFLAGS="-fsanitize=address" -C oss-fuzz # check if dmake needs to be rerun (this job may fail) - name: "rerun dmake?" diff --git a/CMakeLists.txt b/CMakeLists.txt index d3d279c70..e58af49aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,5 +28,6 @@ add_subdirectory(cli) # Client application add_subdirectory(test) # Tests ADD_SUBDIRECTORY(gui) # Graphical application ADD_SUBDIRECTORY(tools/triage) # Triage tool +add_subdirectory(oss-fuzz) # OSS-Fuzz clients include(cmake/printInfo.cmake REQUIRED) diff --git a/externals/simplecpp/CMakeLists.txt b/externals/simplecpp/CMakeLists.txt index 90d22f77f..929853614 100644 --- a/externals/simplecpp/CMakeLists.txt +++ b/externals/simplecpp/CMakeLists.txt @@ -2,5 +2,9 @@ file(GLOB hdrs "*.h") file(GLOB srcs "*.cpp") add_library(simplecpp_objs OBJECT ${srcs} ${hdrs}) +if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_library(simplecpp_objs_sanitized OBJECT ${srcs} ${hdrs}) + target_compile_options(simplecpp_objs_sanitized PRIVATE -fsanitize=address) +endif() diff --git a/externals/tinyxml/CMakeLists.txt b/externals/tinyxml/CMakeLists.txt index 7f05d80ac..b1f96c057 100644 --- a/externals/tinyxml/CMakeLists.txt +++ b/externals/tinyxml/CMakeLists.txt @@ -2,5 +2,9 @@ file(GLOB hdrs "*.h") file(GLOB srcs "*.cpp") add_library(tinyxml_objs OBJECT ${srcs} ${hdrs}) +if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_library(tinyxml_objs_sanitized OBJECT ${srcs} ${hdrs}) + target_compile_options(tinyxml_objs_sanitized PRIVATE -fsanitize=address) +endif() diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index f37939ecb..4d83dda71 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -37,4 +37,7 @@ else() endif() add_library(lib_objs OBJECT ${srcs_lib} ${hdrs}) - +if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_library(lib_objs_sanitized OBJECT ${srcs_lib} ${hdrs}) + target_compile_options(lib_objs_sanitized PRIVATE -fsanitize=address) +endif() diff --git a/oss-fuzz/CMakeLists.txt b/oss-fuzz/CMakeLists.txt new file mode 100644 index 000000000..2eb04ba14 --- /dev/null +++ b/oss-fuzz/CMakeLists.txt @@ -0,0 +1,13 @@ +if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + add_executable(fuzz-client + main.cpp + type2.cpp) + target_include_directories(fuzz-client PRIVATE ${CMAKE_SOURCE_DIR}/lib ${CMAKE_SOURCE_DIR}/externals/simplecpp ${CMAKE_SOURCE_DIR}/externals/tinyxml ${CMAKE_SOURCE_DIR}/externals) + target_compile_options(fuzz-client PRIVATE -fsanitize=fuzzer) + target_link_libraries(fuzz-client PRIVATE simplecpp_objs_sanitized tinyxml_objs_sanitized lib_objs_sanitized) + target_link_options(fuzz-client PRIVATE -fsanitize=address -fsanitize=fuzzer) + + add_executable(translate + translate.cpp + type2.cpp) +endif() \ No newline at end of file diff --git a/oss-fuzz/main.cpp b/oss-fuzz/main.cpp index c564a9787..827f84cd4 100644 --- a/oss-fuzz/main.cpp +++ b/oss-fuzz/main.cpp @@ -19,11 +19,22 @@ public: cppcheck.check("test.cpp", code); } - void reportOut(const std::string &outmsg) { } - void reportErr(const ErrorLogger::ErrorMessage &msg) {} + void reportOut(const std::string &outmsg) OVERRIDE { + (void)outmsg; + } + void reportErr(const ErrorLogger::ErrorMessage &msg) OVERRIDE { + (void)msg; + } void reportProgress(const std::string& filename, const char stage[], - const unsigned int value) {} + const std::size_t value) OVERRIDE { + (void)filename; + (void)stage; + (void)value; + } + void bughuntingReport(const std::string &str) OVERRIDE { + (void)str; + } };