Skip to content

Commit 1858014

Browse files
spencerjacksonkevinAlbseramongodb
authored
CDRIVER-5676 implement bson_validate libfuzzer entrypoint (#1705)
* Add a fuzzer for bson_validate * Use new fno-sanitize-recover format * Update src/libbson/fuzz/fuzz_test_validate.c Co-authored-by: Kevin Albertson <[email protected]> * Update src/libbson/fuzz/fuzz_test_validate.c Co-authored-by: Ezra Chung <[email protected]> --------- Co-authored-by: Kevin Albertson <[email protected]> Co-authored-by: Ezra Chung <[email protected]>
1 parent eae52c0 commit 1858014

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

build/cmake/Sanitizers.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ string(REPLACE ";" "," _sanitize "${MONGO_SANITIZE}")
3535
if (_sanitize)
3636
string (MAKE_C_IDENTIFIER "HAVE_SANITIZE_${_sanitize}" ident)
3737
string (TOUPPER "${ident}" varname)
38-
set (flag "-fsanitize=${_sanitize}")
38+
set (flag -fsanitize=${_sanitize} -fno-sanitize-recover=all)
3939

4040
cmake_push_check_state ()
4141
set (CMAKE_REQUIRED_FLAGS "${flag}")

src/libbson/fuzz/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,8 @@ add_executable(fuzz_test_init_from_json EXCLUDE_FROM_ALL
22
fuzz_test_init_from_json.c)
33
target_link_libraries(fuzz_test_init_from_json PRIVATE bson_static)
44
set_property(TARGET fuzz_test_init_from_json APPEND PROPERTY LINK_OPTIONS -fsanitize=fuzzer)
5+
6+
add_executable(fuzz_test_validate EXCLUDE_FROM_ALL
7+
fuzz_test_validate.c)
8+
target_link_libraries(fuzz_test_validate PRIVATE bson_static)
9+
set_property(TARGET fuzz_test_validate APPEND PROPERTY LINK_OPTIONS -fsanitize=fuzzer)

src/libbson/fuzz/fuzz_test_validate.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <stdlib.h>
2+
#include <stdio.h>
3+
#include <stdint.h>
4+
#include <bson/bson.h>
5+
6+
int
7+
LLVMFuzzerTestOneInput (const uint8_t *data, size_t size)
8+
{
9+
bson_t b;
10+
if (bson_init_static (&b, data, size)) {
11+
bson_validate (&b,
12+
BSON_VALIDATE_UTF8 | BSON_VALIDATE_DOLLAR_KEYS | BSON_VALIDATE_DOT_KEYS |
13+
BSON_VALIDATE_UTF8_ALLOW_NULL | BSON_VALIDATE_EMPTY_KEYS,
14+
NULL);
15+
return 0;
16+
}
17+
return -1;
18+
}

0 commit comments

Comments
 (0)