Skip to content

CDRIVER-5676 implement bson_validate libfuzzer entrypoint #1705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build/cmake/Sanitizers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ string(REPLACE ";" "," _sanitize "${MONGO_SANITIZE}")
if (_sanitize)
string (MAKE_C_IDENTIFIER "HAVE_SANITIZE_${_sanitize}" ident)
string (TOUPPER "${ident}" varname)
set (flag "-fsanitize=${_sanitize}")
set (flag -fsanitize=${_sanitize} -fno-sanitize-recover=all)

cmake_push_check_state ()
set (CMAKE_REQUIRED_FLAGS "${flag}")
Expand Down
5 changes: 5 additions & 0 deletions src/libbson/fuzz/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ add_executable(fuzz_test_init_from_json EXCLUDE_FROM_ALL
fuzz_test_init_from_json.c)
target_link_libraries(fuzz_test_init_from_json PRIVATE bson_static)
set_property(TARGET fuzz_test_init_from_json APPEND PROPERTY LINK_OPTIONS -fsanitize=fuzzer)

add_executable(fuzz_test_validate EXCLUDE_FROM_ALL
fuzz_test_validate.c)
target_link_libraries(fuzz_test_validate PRIVATE bson_static)
set_property(TARGET fuzz_test_validate APPEND PROPERTY LINK_OPTIONS -fsanitize=fuzzer)
18 changes: 18 additions & 0 deletions src/libbson/fuzz/fuzz_test_validate.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <bson/bson.h>

int
LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
{
bson_t b;
if (bson_init_static (&b, data, size)) {
bson_validate (&b,
BSON_VALIDATE_UTF8 | BSON_VALIDATE_DOLLAR_KEYS | BSON_VALIDATE_DOT_KEYS |
BSON_VALIDATE_UTF8_ALLOW_NULL | BSON_VALIDATE_EMPTY_KEYS,
NULL);
return 0;
}
return -1;
}