Fix wolfSSL_Init error handling

This commit is contained in:
Eric Blankenhorn
2022-07-15 09:30:30 -05:00
parent 8a757ef7cf
commit e7303d697b

View File

@ -5479,13 +5479,15 @@ int wolfSSL_Init(void)
}
#ifdef HAVE_GLOBAL_RNG
if ((ret == WOLFSSL_SUCCESS) && (wc_InitMutex(&globalRNGMutex) != 0)) {
if (ret == WOLFSSL_SUCCESS) {
if (wc_InitMutex(&globalRNGMutex) != 0) {
WOLFSSL_MSG("Bad Init Mutex rng");
ret = BAD_MUTEX_E;
}
else {
globalRNGMutex_valid = 1;
}
}
#endif
#ifdef WC_RNG_SEED_CB
@ -5520,33 +5522,37 @@ int wolfSSL_Init(void)
}
}
#else
if ((ret == WOLFSSL_SUCCESS) && (wc_InitMutex(&session_mutex) != 0)) {
if (ret == WOLFSSL_SUCCESS) {
if (wc_InitMutex(&session_mutex) != 0) {
WOLFSSL_MSG("Bad Init Mutex session");
ret = BAD_MUTEX_E;
}
else {
session_mutex_valid = 1;
}
}
#endif
#ifndef NO_CLIENT_CACHE
if ((ret == WOLFSSL_SUCCESS) &&
(wc_InitMutex(&clisession_mutex) != 0)) {
if (ret == WOLFSSL_SUCCESS) {
if (wc_InitMutex(&clisession_mutex) != 0) {
WOLFSSL_MSG("Bad Init Mutex session");
ret = BAD_MUTEX_E;
}
else {
clisession_mutex_valid = 1;
}
}
#endif
#endif
if ((ret == WOLFSSL_SUCCESS) && (wc_InitMutex(&count_mutex) != 0)) {
if (ret == WOLFSSL_SUCCESS) {
if (wc_InitMutex(&count_mutex) != 0) {
WOLFSSL_MSG("Bad Init Mutex count");
ret = BAD_MUTEX_E;
}
else {
count_mutex_valid = 1;
}
}
#if defined(OPENSSL_EXTRA) && defined(HAVE_ATEXIT)
/* OpenSSL registers cleanup using atexit */
if ((ret == WOLFSSL_SUCCESS) && (atexit(AtExitCleanup) != 0)) {
@ -5556,7 +5562,8 @@ int wolfSSL_Init(void)
#endif
}
if ((ret == WOLFSSL_SUCCESS) && (wc_LockMutex(&count_mutex) != 0)) {
if (ret == WOLFSSL_SUCCESS) {
if (wc_LockMutex(&count_mutex) != 0) {
WOLFSSL_MSG("Bad Lock Mutex count");
ret = BAD_MUTEX_E;
}
@ -5564,6 +5571,7 @@ int wolfSSL_Init(void)
initRefCount++;
wc_UnLockMutex(&count_mutex);
}
}
if (ret != WOLFSSL_SUCCESS) {
initRefCount = 1; /* Force cleanup */
@ -5574,7 +5582,6 @@ int wolfSSL_Init(void)
}
#ifndef NO_CERTS
/* process user cert chain to pass during the handshake */