Skip to content

Commit

Permalink
pkcs7: provide fuzz harness
Browse files Browse the repository at this point in the history
This allows for pkcs7 fuzz testing with OSS-Fuzz.

Signed-off-by: Daniel Axtens <[email protected]>
  • Loading branch information
daxtens authored and naynajain committed Jun 15, 2020
1 parent 813d402 commit ff6bb5a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions programs/fuzz/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ if(NOT FUZZINGENGINE_LIB)
add_executable(fuzz_pubkey fuzz_pubkey.c onefile.c)
target_link_libraries(fuzz_pubkey ${libs})

add_executable(fuzz_pkcs7 fuzz_pkcs7.c onefile.c)
target_link_libraries(fuzz_pkcs7 ${libs})

add_executable(fuzz_client fuzz_client.c common.c onefile.c)
target_link_libraries(fuzz_client ${libs})

Expand Down Expand Up @@ -62,6 +65,10 @@ else()
target_link_libraries(fuzz_pubkey ${libs} FuzzingEngine)
SET_TARGET_PROPERTIES(fuzz_pubkey PROPERTIES LINKER_LANGUAGE CXX)

add_executable(fuzz_pkcs7 fuzz_pkcs7.c)
target_link_libraries(fuzz_pkcs7 ${libs} FuzzingEngine)
SET_TARGET_PROPERTIES(fuzz_pkcs7 PROPERTIES LINKER_LANGUAGE CXX)

add_executable(fuzz_client fuzz_client.c common.c)
target_link_libraries(fuzz_client ${libs} FuzzingEngine)
SET_TARGET_PROPERTIES(fuzz_client PROPERTIES LINKER_LANGUAGE CXX)
Expand Down
19 changes: 19 additions & 0 deletions programs/fuzz/fuzz_pkcs7.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <stdint.h>
#include "mbedtls/pkcs7.h"

int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
#ifdef MBEDTLS_PKCS7_USE_C
mbedtls_pkcs7 pkcs7;

mbedtls_pkcs7_init( &pkcs7 );

mbedtls_pkcs7_parse_der( Data, Size, &pkcs7 );

mbedtls_pkcs7_free( &pkcs7 );
#else
(void) Data;
(void) Size;
#endif

return 0;
}
2 changes: 2 additions & 0 deletions programs/fuzz/fuzz_pkcs7.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[libfuzzer]
max_len = 65535

0 comments on commit ff6bb5a

Please sign in to comment.