From a1dc3e5a6058d05cfe6a464261072deb090c7fa6 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Mon, 14 Feb 2022 18:26:21 +0000 Subject: [PATCH] Add safety to dummy_random in case of NULL context Signed-off-by: Paul Elliott --- programs/fuzz/common.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/programs/fuzz/common.c b/programs/fuzz/common.c index e12ee3b8a..465a76e45 100644 --- a/programs/fuzz/common.c +++ b/programs/fuzz/common.c @@ -60,8 +60,11 @@ int dummy_random( void *p_rng, unsigned char *output, size_t output_len ) size_t i; #if defined(MBEDTLS_CTR_DRBG_C) - //use mbedtls_ctr_drbg_random to find bugs in it - ret = mbedtls_ctr_drbg_random(p_rng, output, output_len); + //mbedtls_ctr_drbg_random requires a valid mbedtls_ctr_drbg_context in p_rng + if( p_rng != NULL ) { + //use mbedtls_ctr_drbg_random to find bugs in it + ret = mbedtls_ctr_drbg_random(p_rng, output, output_len); + } #else (void) p_rng; ret = 0;