mrc0mmand / rpms / openldap

Forked from rpms/openldap 3 years ago
Clone

Blame SOURCES/openldap-temporary-ssl-thr-init-race.patch

76092a
Temporary patch that fixes a thread initialization race condition when
76092a
using secure connection.
76092a
76092a
This patch is *not* correct, as the problem only happens when using
76092a
NSS. Either the code in tls_m.c is broken, or the nspr library call
76092a
(PR_CallOnce) doesn't work as expected.
76092a
76092a
Resolves: #1294385
76092a
Backported-From: #1144294
76092a
76092a
--- a/libraries/libldap/tls2.c    2014-09-19 03:48:49.000000000 +0200
76092a
+++ b/libraries/libldap/tls2.c    2015-05-21 09:32:21.034395985 +0200
76092a
@@ -149,6 +149,9 @@ ldap_pvt_tls_destroy( void )
76092a
 	tls_imp->ti_tls_destroy();
76092a
 }
76092a
 
76092a
+#ifdef LDAP_R_COMPILE
76092a
+static pthread_once_t tlsm_initialized = PTHREAD_ONCE_INIT;
76092a
+#endif
76092a
 /*
76092a
  * Initialize a particular TLS implementation.
76092a
  * Called once per implementation.
76092a
@@ -158,6 +161,10 @@ tls_init(tls_impl *impl )
76092a
 {
76092a
 	static int tls_initialized = 0;
76092a
 
76092a
+#ifdef LDAP_R_COMPILE
76092a
+	(void)pthread_once(&tlsm_initialized, impl->ti_thr_init);
76092a
+#endif
76092a
+
76092a
 	if ( !tls_initialized++ ) {
76092a
 #ifdef LDAP_R_COMPILE
76092a
 		ldap_pvt_thread_mutex_init( &tls_def_ctx_mutex );
76092a
@@ -166,9 +173,6 @@ tls_init(tls_impl *impl )
76092a
 
76092a
 	if ( impl->ti_inited++ ) return 0;
76092a
 
76092a
-#ifdef LDAP_R_COMPILE
76092a
-	impl->ti_thr_init();
76092a
-#endif
76092a
 	return impl->ti_tls_init();
76092a
 }