From 7ecd6c5186f3958b726edb3f5e5851f12ad56485 Mon Sep 17 00:00:00 2001 From: Bernd Edlinger Date: Tue, 30 Oct 2018 21:02:22 +0100 Subject: [PATCH] Fix error handling in drbgtest.c Reviewed-by: Matthias St. Pierre Reviewed-by: Paul Dale (Merged from https://github.com/openssl/openssl/pull/7517) --- test/drbgtest.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/test/drbgtest.c b/test/drbgtest.c index 882fef82d4..a3beebc774 100644 --- a/test/drbgtest.c +++ b/test/drbgtest.c @@ -799,12 +799,15 @@ static void run_multi_thread_test(void) { unsigned char buf[256]; time_t start = time(NULL); - RAND_DRBG *public, *private; + RAND_DRBG *public = NULL, *private = NULL; - public = RAND_DRBG_get0_public(); - private = RAND_DRBG_get0_private(); - RAND_DRBG_set_reseed_time_interval(public, 1); + if (!TEST_ptr(public = RAND_DRBG_get0_public()) + || !TEST_ptr(private = RAND_DRBG_get0_private())) { + multi_thread_rand_bytes_succeeded = 0; + return; + } RAND_DRBG_set_reseed_time_interval(private, 1); + RAND_DRBG_set_reseed_time_interval(public, 1); do { if (RAND_bytes(buf, sizeof(buf)) <= 0) @@ -936,13 +939,16 @@ static size_t rand_drbg_seedlen(RAND_DRBG *drbg) */ static int test_rand_seed(void) { - RAND_DRBG *master = RAND_DRBG_get0_master(); + RAND_DRBG *master = NULL; unsigned char rand_buf[256]; size_t rand_buflen; -#ifdef OPENSSL_RAND_SEED_NONE - size_t required_seed_buflen = rand_drbg_seedlen(master); -#else size_t required_seed_buflen = 0; + + if (!TEST_ptr(master = RAND_DRBG_get0_master())) + return 0; + +#ifdef OPENSSL_RAND_SEED_NONE + required_seed_buflen = rand_drbg_seedlen(master); #endif memset(rand_buf, 0xCD, sizeof(rand_buf)); @@ -1025,14 +1031,13 @@ err: static int test_set_defaults(void) { - RAND_DRBG *master, *public, *private; - - master = RAND_DRBG_get0_master(); - public = RAND_DRBG_get0_public(); - private = RAND_DRBG_get0_private(); + RAND_DRBG *master = NULL, *public = NULL, *private = NULL; /* Check the default type and flags for master, public and private */ - return TEST_int_eq(master->type, RAND_DRBG_TYPE) + return TEST_ptr(master = RAND_DRBG_get0_master()) + && TEST_ptr(public = RAND_DRBG_get0_public()) + && TEST_ptr(private = RAND_DRBG_get0_private()) + && TEST_int_eq(master->type, RAND_DRBG_TYPE) && TEST_int_eq(master->flags, RAND_DRBG_FLAGS | RAND_DRBG_FLAG_MASTER) && TEST_int_eq(public->type, RAND_DRBG_TYPE) -- 2.25.1