From 8cd5d436394f5aeb7c500f3c695aba8d64b10ded Mon Sep 17 00:00:00 2001 From: Hanno Becker Date: Fri, 8 Sep 2017 10:35:32 +0100 Subject: [PATCH] Initialize RSA context in RSA test suite before first potentially failing operation The function `rsa_gen_key` from `test_suite_rsa.function` initialized a stack allocated RSA context only after seeding the CTR DRBG. If the latter operation failed, the cleanup code tried to free the uninitialized RSA context, potentially resulting in a segmentation fault. Fixes one aspect of #1023. --- tests/suites/test_suite_rsa.function | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/suites/test_suite_rsa.function b/tests/suites/test_suite_rsa.function index d4f330805..7cfc09f7f 100644 --- a/tests/suites/test_suite_rsa.function +++ b/tests/suites/test_suite_rsa.function @@ -667,12 +667,12 @@ void rsa_gen_key( int nrbits, int exponent, int result) const char *pers = "test_suite_rsa"; entropy_init( &entropy ); + rsa_init( &ctx, 0, 0 ); + TEST_ASSERT( ctr_drbg_init( &ctr_drbg, entropy_func, &entropy, (const unsigned char *) pers, strlen( pers ) ) == 0 ); - rsa_init( &ctx, 0, 0 ); - TEST_ASSERT( rsa_gen_key( &ctx, ctr_drbg_random, &ctr_drbg, nrbits, exponent ) == result ); if( result == 0 )