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
if ((ret == WOLFSSL_SUCCESS) && (wc_InitMutex(&globalRNGMutex) != 0)) {
WOLFSSL_MSG("Bad Init Mutex rng");
ret = BAD_MUTEX_E;
}
else {
globalRNGMutex_valid = 1;
if (ret == WOLFSSL_SUCCESS) {
if (wc_InitMutex(&globalRNGMutex) != 0) {
WOLFSSL_MSG("Bad Init Mutex rng");
ret = BAD_MUTEX_E;
}
else {
globalRNGMutex_valid = 1;
}
}
#endif
@ -5520,33 +5522,37 @@ int wolfSSL_Init(void)
}
}
#else
if ((ret == WOLFSSL_SUCCESS) && (wc_InitMutex(&session_mutex) != 0)) {
WOLFSSL_MSG("Bad Init Mutex session");
ret = BAD_MUTEX_E;
}
else {
session_mutex_valid = 1;
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)) {
WOLFSSL_MSG("Bad Init Mutex session");
ret = BAD_MUTEX_E;
}
else {
clisession_mutex_valid = 1;
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)) {
WOLFSSL_MSG("Bad Init Mutex count");
ret = BAD_MUTEX_E;
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;
}
}
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,13 +5562,15 @@ int wolfSSL_Init(void)
#endif
}
if ((ret == WOLFSSL_SUCCESS) && (wc_LockMutex(&count_mutex) != 0)) {
WOLFSSL_MSG("Bad Lock Mutex count");
ret = BAD_MUTEX_E;
}
else {
initRefCount++;
wc_UnLockMutex(&count_mutex);
if (ret == WOLFSSL_SUCCESS) {
if (wc_LockMutex(&count_mutex) != 0) {
WOLFSSL_MSG("Bad Lock Mutex count");
ret = BAD_MUTEX_E;
}
else {
initRefCount++;
wc_UnLockMutex(&count_mutex);
}
}
if (ret != WOLFSSL_SUCCESS) {
@ -5574,7 +5582,6 @@ int wolfSSL_Init(void)
}
#ifndef NO_CERTS
/* process user cert chain to pass during the handshake */