From 845c4a543c091f5951b5e5b2063531ad264da6d1 Mon Sep 17 00:00:00 2001 From: Yakov Olkhovskiy Date: Thu, 10 Oct 2024 18:59:48 +0000 Subject: [PATCH] add test for libfuzzer --- utils/CMakeLists.txt | 4 ++++ utils/libfuzzer-test/CMakeLists.txt | 1 + utils/libfuzzer-test/README.md | 1 + utils/libfuzzer-test/test_basic_fuzzer/CMakeLists.txt | 1 + utils/libfuzzer-test/test_basic_fuzzer/main.cpp | 11 +++++++++++ 5 files changed, 18 insertions(+) create mode 100644 utils/libfuzzer-test/CMakeLists.txt create mode 100644 utils/libfuzzer-test/README.md create mode 100644 utils/libfuzzer-test/test_basic_fuzzer/CMakeLists.txt create mode 100644 utils/libfuzzer-test/test_basic_fuzzer/main.cpp diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index ec44a1e1de9..8c706ee6b67 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -23,3 +23,7 @@ if (ENABLE_UTILS) add_subdirectory (keeper-data-dumper) add_subdirectory (memcpy-bench) endif () + +if (ENABLE_FUZZING) + add_subdirectory (libfuzzer-test) +endif () diff --git a/utils/libfuzzer-test/CMakeLists.txt b/utils/libfuzzer-test/CMakeLists.txt new file mode 100644 index 00000000000..8765787ff8a --- /dev/null +++ b/utils/libfuzzer-test/CMakeLists.txt @@ -0,0 +1 @@ +add_subdirectory (test_basic_fuzzer) diff --git a/utils/libfuzzer-test/README.md b/utils/libfuzzer-test/README.md new file mode 100644 index 00000000000..5598cbdb961 --- /dev/null +++ b/utils/libfuzzer-test/README.md @@ -0,0 +1 @@ +This folder contains various stuff intended to test libfuzzer functionality. diff --git a/utils/libfuzzer-test/test_basic_fuzzer/CMakeLists.txt b/utils/libfuzzer-test/test_basic_fuzzer/CMakeLists.txt new file mode 100644 index 00000000000..dc927f35a4b --- /dev/null +++ b/utils/libfuzzer-test/test_basic_fuzzer/CMakeLists.txt @@ -0,0 +1 @@ +add_executable (test_basic_fuzzer main.cpp) diff --git a/utils/libfuzzer-test/test_basic_fuzzer/main.cpp b/utils/libfuzzer-test/test_basic_fuzzer/main.cpp new file mode 100644 index 00000000000..7ccad63273d --- /dev/null +++ b/utils/libfuzzer-test/test_basic_fuzzer/main.cpp @@ -0,0 +1,11 @@ +#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; +}