From 9ce1329ff1e87e6f05f764b4b659207391f4d183 Mon Sep 17 00:00:00 2001 From: filipecosta90 Date: Tue, 5 Apr 2022 14:47:39 +0100 Subject: [PATCH 1/3] Kicking off fuzz testing with libfuzzer --- CMakeLists.txt | 1 + Makefile | 1 + tests/CMakeLists.txt | 15 +++++++++++++++ tests/test_fuzzer.cc | 10 ++++++++++ 4 files changed, 27 insertions(+) create mode 100644 tests/test_fuzzer.cc diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c24767..264271b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,6 +12,7 @@ option(BUILD_BENCHMARK "Build benchmark" ON) option(BUILD_TESTS "Build tests" ON) OPTION(ENABLE_CODECOVERAGE "Enable code coverage testing support" OFF) OPTION(ENABLE_PROFILE "Enable code profiling support" OFF) +option(ENABLE_FUZZER "Enable fuzz testing" OFF) option(BUILD_EXAMPLES "Build examples" ON) # --- Build properties --- diff --git a/Makefile b/Makefile index db8f06a..3bc9cf0 100644 --- a/Makefile +++ b/Makefile @@ -77,6 +77,7 @@ ifndef CMAKE_TEST_OPTIONS CMAKE_TEST_OPTIONS=\ -DBUILD_SHARED=ON \ -DBUILD_STATIC=ON \ + -DENABLE_FUZZER=ON \ -DBUILD_TESTS=ON \ -DENABLE_CODECOVERAGE=ON \ -DBUILD_BENCHMARK=OFF \ diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5163a06..a24686c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -18,3 +18,18 @@ add_executable(td_test td_test.c minunit.h) target_link_libraries(td_test tdigest m) enable_testing() add_test(td_test td_test) + + +# --- Fuzz testing --- +if (ENABLE_FUZZER) + message(STATUS "Forcing compiler to be clang given we're using libfuzz.") + set(CMAKE_C_COMPILER clang) + set(CMAKE_CXX_COMPILER clang) + add_executable(td_fuzz test_fuzzer.cc) + target_compile_options(td_fuzz PRIVATE $<$:-g -O1 + -fsanitize=fuzzer>) + + target_link_libraries(td_fuzz + PRIVATE $<$:-fsanitize=fuzzer> tdigest) + add_test(td_fuzz td_fuzz) +endif() diff --git a/tests/test_fuzzer.cc b/tests/test_fuzzer.cc new file mode 100644 index 0000000..8b83386 --- /dev/null +++ b/tests/test_fuzzer.cc @@ -0,0 +1,10 @@ +// Test_fuzzer.cc +#include +#include +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + if (size > 0 && data[0] == 'H') + if (size > 1 && data[1] == 'I') + if (size > 2 && data[2] == '!') + __builtin_trap(); + return 0; +} \ No newline at end of file From 736fbce8a4259cd6dc4893c26129fe8e65f1cda2 Mon Sep 17 00:00:00 2001 From: filipecosta90 Date: Tue, 5 Apr 2022 14:50:28 +0100 Subject: [PATCH 2/3] circleci fix apt update --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 6d1e489..540f90c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -19,7 +19,7 @@ jobs: - checkout - run: name: Install CMAKE - command: 'apt install -y cmake' + command: 'apt install -y cmake --fix-missing' - run: name: Pull Submodules command: git submodule update --init --recursive From 8e894e03a56486ee69aa30079e4120705725e52d Mon Sep 17 00:00:00 2001 From: filipecosta90 Date: Tue, 5 Apr 2022 14:56:17 +0100 Subject: [PATCH 3/3] using silkeh/clang:12 --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 540f90c..c4b2ce9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -4,7 +4,7 @@ version: 2.1 jobs: lint: docker: - - image: redislabsmodules/llvm-toolset:latest + - image: silkeh/clang:12 steps: - checkout - run: @@ -14,7 +14,7 @@ jobs: sanitize: docker: - - image: redislabsmodules/llvm-toolset:latest + - image: silkeh/clang:12 steps: - checkout - run: