fuzz_x509crt.c (927B)
1 #include <stdint.h> 2 #include "mbedtls/x509_crt.h" 3 #include "common.h" 4 5 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) 6 { 7 #ifdef MBEDTLS_X509_CRT_PARSE_C 8 int ret; 9 mbedtls_x509_crt crt; 10 unsigned char buf[4096]; 11 12 mbedtls_x509_crt_init(&crt); 13 #if defined(MBEDTLS_USE_PSA_CRYPTO) 14 psa_status_t status = psa_crypto_init(); 15 if (status != PSA_SUCCESS) { 16 goto exit; 17 } 18 #endif /* MBEDTLS_USE_PSA_CRYPTO */ 19 ret = mbedtls_x509_crt_parse(&crt, Data, Size); 20 #if !defined(MBEDTLS_X509_REMOVE_INFO) 21 if (ret == 0) { 22 ret = mbedtls_x509_crt_info((char *) buf, sizeof(buf) - 1, " ", &crt); 23 } 24 #else 25 ((void) ret); 26 ((void) buf); 27 #endif /* !MBEDTLS_X509_REMOVE_INFO */ 28 29 #if defined(MBEDTLS_USE_PSA_CRYPTO) 30 exit: 31 mbedtls_psa_crypto_free(); 32 #endif /* MBEDTLS_USE_PSA_CRYPTO */ 33 mbedtls_x509_crt_free(&crt); 34 #else 35 (void) Data; 36 (void) Size; 37 #endif 38 39 return 0; 40 }