Skip to content

Commit 8e8e9bd

Browse files
committed
src/ssl.c: fix races in wolfSSL_Init() and wolfSSL_RAND_bytes().
1 parent 460991a commit 8e8e9bd

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/ssl.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5757,12 +5757,13 @@ int wolfSSL_Init(void)
57575757

57585758
if (ret == WOLFSSL_SUCCESS) {
57595759
initRefCount++;
5760+
} else {
5761+
initRefCount = 1; /* Force cleanup */
57605762
}
57615763

57625764
wc_UnLockMutex(&inits_count_mutex);
57635765

57645766
if (ret != WOLFSSL_SUCCESS) {
5765-
initRefCount = 1; /* Force cleanup */
57665767
(void)wolfSSL_Cleanup(); /* Ignore any error from cleanup */
57675768
}
57685769

@@ -23923,18 +23924,22 @@ int wolfSSL_RAND_bytes(unsigned char* buf, int num)
2392323924
}
2392423925
#endif
2392523926
#ifdef HAVE_GLOBAL_RNG
23926-
if (initGlobalRNG) {
23927-
if (wc_LockMutex(&globalRNGMutex) != 0) {
23928-
WOLFSSL_MSG("Bad Lock Mutex rng");
23929-
return ret;
23930-
}
23927+
if (wc_LockMutex(&globalRNGMutex) != 0) {
23928+
WOLFSSL_MSG("Bad Lock Mutex rng");
23929+
return ret;
23930+
}
2393123931

23932+
if (initGlobalRNG) {
2393223933
rng = &globalRNG;
2393323934
used_global = 1;
2393423935
}
2393523936
else
2393623937
#endif
2393723938
{
23939+
#ifdef HAVE_GLOBAL_RNG
23940+
wc_UnLockMutex(&globalRNGMutex);
23941+
#endif
23942+
2393823943
#ifdef WOLFSSL_SMALL_STACK
2393923944
tmpRNG = (WC_RNG*)XMALLOC(sizeof(WC_RNG), NULL, DYNAMIC_TYPE_RNG);
2394023945
if (tmpRNG == NULL)

0 commit comments

Comments
 (0)