Skip to content

Commit 0be392b

Browse files
authored
MONGOCRYPT-834 fuzzing for oss-fuzz (#1152)
1 parent 54d1959 commit 0be392b

25 files changed

Lines changed: 584 additions & 0 deletions

CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,25 @@ if (NOT MONGOCRYPT_CRYPTO STREQUAL none)
592592
endif ()
593593
endif ()
594594

595+
option (ENABLE_FUZZING "Build fuzzing targets. Requires a compiler supporting -fsanitize=fuzzer." OFF)
596+
if (ENABLE_FUZZING)
597+
include (CheckCCompilerFlag)
598+
set (CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
599+
check_c_compiler_flag ("-fsanitize=fuzzer-no-link" COMPILER_SUPPORTS_FUZZER)
600+
unset (CMAKE_TRY_COMPILE_TARGET_TYPE)
601+
if (NOT COMPILER_SUPPORTS_FUZZER)
602+
message (FATAL_ERROR
603+
"ENABLE_FUZZING is ON but the compiler does not support -fsanitize=fuzzer. "
604+
)
605+
endif ()
606+
607+
add_executable (fuzz_mongocrypt EXCLUDE_FROM_ALL test/fuzz_mongocrypt.c)
608+
target_include_directories (fuzz_mongocrypt PRIVATE ./src)
609+
target_link_libraries (fuzz_mongocrypt PRIVATE mongocrypt_static _mongocrypt::libbson_for_static)
610+
target_compile_options (fuzz_mongocrypt PRIVATE -fsanitize=fuzzer)
611+
target_link_options (fuzz_mongocrypt PRIVATE -fsanitize=fuzzer)
612+
endif ()
613+
595614
if (ENABLE_STATIC)
596615
set (TARGETS_TO_INSTALL mongocrypt mongocrypt_static)
597616
else ()
9 Bytes
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
HTTP/1.1 200 OK
2+
Transfer-Encoding: chunked
3+
4+
7fffffff
5+
X
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
HTTP/1.1 200 OK
2+
Transfer-Encoding: chunked
3+
4+
7fffffff
26 Bytes
Binary file not shown.
21 Bytes
Binary file not shown.
23 Bytes
Binary file not shown.
149 Bytes
Binary file not shown.
23 Bytes
Binary file not shown.
6 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)