From 106a0afc5a8819d6f7fc450c66caa5919681cdd5 Mon Sep 17 00:00:00 2001 From: Nayna Jain Date: Tue, 3 Nov 2020 21:07:21 +0000 Subject: [PATCH] pkcs7: provide fuzz harness This allows for pkcs7 fuzz testing with OSS-Fuzz. Signed-off-by: Daniel Axtens Signed-off-by: Nayna Jain --- programs/fuzz/.gitignore | 1 + programs/fuzz/CMakeLists.txt | 1 + programs/fuzz/fuzz_pkcs7.c | 19 +++++++++++++++++++ programs/fuzz/fuzz_pkcs7.options | 2 ++ 4 files changed, 23 insertions(+) create mode 100644 programs/fuzz/fuzz_pkcs7.c create mode 100644 programs/fuzz/fuzz_pkcs7.options diff --git a/programs/fuzz/.gitignore b/programs/fuzz/.gitignore index 5dc096055..34e3ed088 100644 --- a/programs/fuzz/.gitignore +++ b/programs/fuzz/.gitignore @@ -1,6 +1,7 @@ fuzz_client fuzz_dtlsclient fuzz_dtlsserver +fuzz_pkcs7 fuzz_privkey fuzz_pubkey fuzz_server diff --git a/programs/fuzz/CMakeLists.txt b/programs/fuzz/CMakeLists.txt index c7fcd356b..7747744cd 100644 --- a/programs/fuzz/CMakeLists.txt +++ b/programs/fuzz/CMakeLists.txt @@ -12,6 +12,7 @@ set(executables_no_common_c fuzz_x509crl fuzz_x509crt fuzz_x509csr + fuzz_pkcs7 ) set(executables_with_common_c diff --git a/programs/fuzz/fuzz_pkcs7.c b/programs/fuzz/fuzz_pkcs7.c new file mode 100644 index 000000000..960007d7a --- /dev/null +++ b/programs/fuzz/fuzz_pkcs7.c @@ -0,0 +1,19 @@ +#include +#include "mbedtls/pkcs7.h" + +int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { +#ifdef MBEDTLS_PKCS7_C + mbedtls_pkcs7 pkcs7; + + mbedtls_pkcs7_init( &pkcs7 ); + + mbedtls_pkcs7_parse_der( &pkcs7, Data, Size ); + + mbedtls_pkcs7_free( &pkcs7 ); +#else + (void) Data; + (void) Size; +#endif + + return 0; +} diff --git a/programs/fuzz/fuzz_pkcs7.options b/programs/fuzz/fuzz_pkcs7.options new file mode 100644 index 000000000..0824b19fa --- /dev/null +++ b/programs/fuzz/fuzz_pkcs7.options @@ -0,0 +1,2 @@ +[libfuzzer] +max_len = 65535