Skip to content

Commit

Permalink
DRBG: fix coverity issues
Browse files Browse the repository at this point in the history
- drbg_lib.c: Silence coverity warning: the comment preceding the
  RAND_DRBG_instantiate() call explicitely states that the error
  is ignored and explains the reason why.

- drbgtest: Add checks for the return values of RAND_bytes() and
  RAND_priv_bytes() to run_multi_thread_test().

Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from #5976)
  • Loading branch information
mspncp committed Apr 17, 2018
1 parent 826e154 commit 43687d6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
8 changes: 4 additions & 4 deletions crypto/rand/drbg_lib.c
Expand Up @@ -864,14 +864,14 @@ static RAND_DRBG *drbg_setup(RAND_DRBG *parent)
drbg->reseed_counter = 1;

/*
* Ignore instantiation error so support just-in-time instantiation.
* Ignore instantiation error to support just-in-time instantiation.
*
* The state of the drbg will be checked in RAND_DRBG_generate() and
* an automatic recovery is attempted.
*/
RAND_DRBG_instantiate(drbg,
(const unsigned char *) ossl_pers_string,
sizeof(ossl_pers_string) - 1);
(void)RAND_DRBG_instantiate(drbg,
(const unsigned char *) ossl_pers_string,
sizeof(ossl_pers_string) - 1);
return drbg;

err:
Expand Down
16 changes: 13 additions & 3 deletions test/drbgtest.c
Expand Up @@ -783,6 +783,8 @@ static int test_rand_reseed(void)
}

#if defined(OPENSSL_THREADS)
static int multi_thread_rand_bytes_succeeded = 1;
static int multi_thread_rand_priv_bytes_succeeded = 1;

static void run_multi_thread_test(void)
{
Expand All @@ -796,8 +798,10 @@ static void run_multi_thread_test(void)
RAND_DRBG_set_reseed_time_interval(private, 1);

do {
RAND_bytes(buf, sizeof(buf));
RAND_priv_bytes(buf, sizeof(buf));
if (RAND_bytes(buf, sizeof(buf)) <= 0)
multi_thread_rand_bytes_succeeded = 0;
if (RAND_priv_bytes(buf, sizeof(buf)) <= 0)
multi_thread_rand_priv_bytes_succeeded = 0;
}
while(time(NULL) - start < 5);
}
Expand Down Expand Up @@ -849,7 +853,7 @@ static int wait_for_thread(thread_t thread)
* The main thread will also run the test, so we'll have THREADS+1 parallel
* tests running
*/
#define THREADS 3
# define THREADS 3

static int test_multi_thread(void)
{
Expand All @@ -861,6 +865,12 @@ static int test_multi_thread(void)
run_multi_thread_test();
for (i = 0; i < THREADS; i++)
wait_for_thread(t[i]);

if (!TEST_true(multi_thread_rand_bytes_succeeded))
return 0;
if (!TEST_true(multi_thread_rand_priv_bytes_succeeded))
return 0;

return 1;
}
#endif
Expand Down

0 comments on commit 43687d6

Please sign in to comment.