Skip to content

Commit 28cd5d7

Browse files
authored
fixed OSS-Fuzz builds and added CMake targets (cppcheck-opensource#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
1 parent c78e3e7 commit 28cd5d7

7 files changed

Lines changed: 42 additions & 4 deletions

File tree

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ matrix:
164164
- ./testrunner TestSymbolDatabase
165165
# check .json files
166166
- find . -name '*.json' -not -path '*/\.*' | xargs jsonlint -s
167+
# build OSS-Fuzz clients
168+
- make -j2 CXXFLAGS="-fsanitize=address" -C oss-fuzz
167169

168170
# check if dmake needs to be rerun (this job may fail)
169171
- name: "rerun dmake?"

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ add_subdirectory(cli) # Client application
2828
add_subdirectory(test) # Tests
2929
ADD_SUBDIRECTORY(gui) # Graphical application
3030
ADD_SUBDIRECTORY(tools/triage) # Triage tool
31+
add_subdirectory(oss-fuzz) # OSS-Fuzz clients
3132

3233
include(cmake/printInfo.cmake REQUIRED)

externals/simplecpp/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@ file(GLOB hdrs "*.h")
22
file(GLOB srcs "*.cpp")
33

44
add_library(simplecpp_objs OBJECT ${srcs} ${hdrs})
5+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
6+
add_library(simplecpp_objs_sanitized OBJECT ${srcs} ${hdrs})
7+
target_compile_options(simplecpp_objs_sanitized PRIVATE -fsanitize=address)
8+
endif()
59

610

externals/tinyxml/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,9 @@ file(GLOB hdrs "*.h")
22
file(GLOB srcs "*.cpp")
33

44
add_library(tinyxml_objs OBJECT ${srcs} ${hdrs})
5+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
6+
add_library(tinyxml_objs_sanitized OBJECT ${srcs} ${hdrs})
7+
target_compile_options(tinyxml_objs_sanitized PRIVATE -fsanitize=address)
8+
endif()
59

610

lib/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@ else()
3737
endif()
3838

3939
add_library(lib_objs OBJECT ${srcs_lib} ${hdrs})
40-
40+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
41+
add_library(lib_objs_sanitized OBJECT ${srcs_lib} ${hdrs})
42+
target_compile_options(lib_objs_sanitized PRIVATE -fsanitize=address)
43+
endif()

oss-fuzz/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
2+
add_executable(fuzz-client
3+
main.cpp
4+
type2.cpp)
5+
target_include_directories(fuzz-client PRIVATE ${CMAKE_SOURCE_DIR}/lib ${CMAKE_SOURCE_DIR}/externals/simplecpp ${CMAKE_SOURCE_DIR}/externals/tinyxml ${CMAKE_SOURCE_DIR}/externals)
6+
target_compile_options(fuzz-client PRIVATE -fsanitize=fuzzer)
7+
target_link_libraries(fuzz-client PRIVATE simplecpp_objs_sanitized tinyxml_objs_sanitized lib_objs_sanitized)
8+
target_link_options(fuzz-client PRIVATE -fsanitize=address -fsanitize=fuzzer)
9+
10+
add_executable(translate
11+
translate.cpp
12+
type2.cpp)
13+
endif()

oss-fuzz/main.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,22 @@ class CppcheckExecutor : public ErrorLogger {
1919
cppcheck.check("test.cpp", code);
2020
}
2121

22-
void reportOut(const std::string &outmsg) { }
23-
void reportErr(const ErrorLogger::ErrorMessage &msg) {}
22+
void reportOut(const std::string &outmsg) OVERRIDE {
23+
(void)outmsg;
24+
}
25+
void reportErr(const ErrorLogger::ErrorMessage &msg) OVERRIDE {
26+
(void)msg;
27+
}
2428
void reportProgress(const std::string& filename,
2529
const char stage[],
26-
const unsigned int value) {}
30+
const std::size_t value) OVERRIDE {
31+
(void)filename;
32+
(void)stage;
33+
(void)value;
34+
}
35+
void bughuntingReport(const std::string &str) OVERRIDE {
36+
(void)str;
37+
}
2738
};
2839

2940

0 commit comments

Comments
 (0)