Merge pull request #5364 from embhorn/zd14519

Fix wolfSSL_Init error handling
This commit is contained in:
David Garske
2022-07-20 08:03:08 -07:00
committed by GitHub

View File

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