From bb0168144e82ed0f240ebf222db171e46fabe812 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Mon, 14 Feb 2022 15:57:11 +0000 Subject: [PATCH] Ensure valid context is used in fuzz_dtlsserver A valid ctr_drbg context is now a prerequisite for using dummy_random() Signed-off-by: Paul Elliott --- programs/fuzz/fuzz_dtlsserver.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/programs/fuzz/fuzz_dtlsserver.c b/programs/fuzz/fuzz_dtlsserver.c index 9a6e894a8..1aa757c37 100644 --- a/programs/fuzz/fuzz_dtlsserver.c +++ b/programs/fuzz/fuzz_dtlsserver.c @@ -44,6 +44,13 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { unsigned char buf[4096]; fuzzBufferOffset_t biomemfuzz; + mbedtls_ctr_drbg_init( &ctr_drbg ); + mbedtls_entropy_init( &entropy ); + + if( mbedtls_ctr_drbg_seed( &ctr_drbg, dummy_entropy, &entropy, + ( const unsigned char * ) pers, strlen( pers ) ) != 0 ) + goto exit; + if (initialized == 0) { #if defined(MBEDTLS_X509_CRT_PARSE_C) && defined(MBEDTLS_PEM_PARSE_C) mbedtls_x509_crt_init( &srvcert ); @@ -56,7 +63,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { return 1; if (mbedtls_pk_parse_key( &pkey, (const unsigned char *) mbedtls_test_srv_key, mbedtls_test_srv_key_len, NULL, 0, - dummy_random, NULL ) != 0) + dummy_random, &ctr_drbg ) != 0) return 1; #endif dummy_init(); @@ -65,15 +72,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { } mbedtls_ssl_init( &ssl ); mbedtls_ssl_config_init( &conf ); - mbedtls_ctr_drbg_init( &ctr_drbg ); - mbedtls_entropy_init( &entropy ); mbedtls_ssl_cookie_init( &cookie_ctx ); - if( mbedtls_ctr_drbg_seed( &ctr_drbg, dummy_entropy, &entropy, - (const unsigned char *) pers, strlen( pers ) ) != 0 ) - goto exit; - - if( mbedtls_ssl_config_defaults( &conf, MBEDTLS_SSL_IS_SERVER, MBEDTLS_SSL_TRANSPORT_DATAGRAM,