aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatarLibravatar daurnimator <quae@daurnimator.com> 2017-04-04 00:27:57 +1000
committerLibravatarLibravatar daurnimator <quae@daurnimator.com> 2017-08-10 11:52:15 +1000
commit39a4e527933a6b46234ff6f229469a68d9d455ac (patch)
tree0f9c90e274f48839a6b4f234007a4a5c5fc4c9d7 /src
parent5d6b15859e25da8271a3820662bb9d1f8a935107 (diff)
downloadluaossl-39a4e527933a6b46234ff6f229469a68d9d455ac.tar.gz
luaossl-39a4e527933a6b46234ff6f229469a68d9d455ac.tar.bz2
luaossl-39a4e527933a6b46234ff6f229469a68d9d455ac.zip
Use a single lock across multiple init functions
Diffstat (limited to 'src')
-rw-r--r--src/openssl.c39
1 files changed, 13 insertions, 26 deletions
diff --git a/src/openssl.c b/src/openssl.c
index a01fde5..df559d7 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -1781,14 +1781,11 @@ static int compat_X509_up_ref(X509 *crt) {
*/
#endif
+/* compat_init must not be called from multiple threads at once */
static int compat_init(void) {
- static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static int store_index = -1, ssl_ctx_index = -1, done;
int error = 0;
- if ((error = pthread_mutex_lock(&mutex)))
- return error;
-
if (done)
goto epilog;
@@ -1859,8 +1856,6 @@ epilog:
compat.tmp.store = NULL;
}
- (void)pthread_mutex_unlock(&mutex);
-
return error;
sslerr:
error = auxL_EOPENSSL;
@@ -1984,15 +1979,12 @@ static void ex_onfree(void *parent NOTUSED, void *_data, CRYPTO_EX_DATA *ad NOTU
free(data);
} /* ex_onfree() */
+/* ex_init must not be called from multiple threads at once */
static int ex_init(void) {
- static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static int done;
struct ex_type *type;
int error = 0;
- if ((error = pthread_mutex_lock(&mutex)))
- return error;
-
if (done)
goto epilog;
@@ -2013,8 +2005,6 @@ static int ex_init(void) {
done = 1;
epilog:
- (void)pthread_mutex_unlock(&mutex);
-
return error;
sslerr:
error = auxL_EOPENSSL;
@@ -10058,14 +10048,11 @@ static unsigned long mt_gettid(void) {
#endif
} /* mt_gettid() */
+/* mt_init must not be called from multiple threads at once */
static int mt_init(void) {
- static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static int done, bound;
int error = 0;
- if ((error = pthread_mutex_lock(&mutex)))
- return error;
-
if (done)
goto epilog;
@@ -10108,8 +10095,6 @@ static int mt_init(void) {
done = 1;
epilog:
- pthread_mutex_unlock(&mutex);
-
return error;
} /* mt_init() */
@@ -10119,12 +10104,11 @@ static void initall(lua_State *L) {
static int initssl;
int error;
- if ((error = mt_init()))
- auxL_error(L, error, "openssl.init");
-
pthread_mutex_lock(&mutex);
- if (!initssl) {
+ error = mt_init();
+
+ if (!error && !initssl) {
initssl = 1;
SSL_load_error_strings();
@@ -10138,12 +10122,15 @@ static void initall(lua_State *L) {
OPENSSL_config(NULL);
}
- pthread_mutex_unlock(&mutex);
+ if (!error)
+ error = compat_init();
- if ((error = compat_init()))
- auxL_error(L, error, "openssl.init");
+ if (!error)
+ error = ex_init();
+
+ pthread_mutex_unlock(&mutex);
- if ((error = ex_init()))
+ if (error)
auxL_error(L, error, "openssl.init");
ex_newstate(L);