components/openldap/patches/08-mutex-init.patch
author David Hollister <david.hollister@oracle.com>
Wed, 12 Oct 2016 14:01:13 -0600
changeset 7094 61352b4e5af5
parent 6377 12498e4ad8f9
permissions -rw-r--r--
24797203 OpenStack RBAC profiles allow reading too many files 24797238 keystone RBAC and SMF should point at Apache log files 24797256 cinder RBAC and SMF should point at Apache log files 24830959 horizon RBAC and SMF should point at Apache log files

Fixes a race condition that can be triggered when multiple threads
enter the function ldap_int_utils_init about the same time.
Patch was developed in-house; it is Solaris specific and
will not be contributed upstream.

--- openldap-2.4.44/libraries/libldap/util-int.c.old	2016-06-28 12:13:02.410770969 -0700
+++ openldap-2.4.44/libraries/libldap/util-int.c	2016-06-28 12:13:07.923164035 -0700
@@ -92,6 +92,10 @@
 	/* Don't know how to handle this version, pretend it's not there */
 #	undef HAVE_GETHOSTBYADDR_R
 # endif
+
+/* use static mutex to protect mutex initialization */
+static ldap_pvt_thread_mutex_t ldap_int_utils_init_mutex = PTHREAD_MUTEX_INITIALIZER;
+
 #endif /* LDAP_R_COMPILE */
 
 char *ldap_pvt_ctime( const time_t *tp, char *buf )
@@ -700,9 +704,17 @@
 	static int done=0;
 	if (done)
 	  return;
+#ifndef LDAP_R_COMPILE
	done=1;
+#endif
 
 #ifdef LDAP_R_COMPILE
+	/* use static mutex to protect mutex initialization */
+	(void) LDAP_MUTEX_LOCK(&ldap_int_utils_init_mutex);
+	if (done) {
+		(void) LDAP_MUTEX_UNLOCK(&ldap_int_utils_init_mutex);
+		return;
+	}
 #if !defined( USE_CTIME_R ) && !defined( HAVE_REENTRANT_FUNCTIONS )
 	ldap_pvt_thread_mutex_init( &ldap_int_ctime_mutex );
 #endif
@@ -718,9 +727,13 @@
 #ifdef HAVE_GSSAPI
 	ldap_pvt_thread_mutex_init( &ldap_int_gssapi_mutex );
 #endif
+ 
+	done=1;
+	/* use static mutex to protect mutex initialization */
+	(void) LDAP_MUTEX_UNLOCK(&ldap_int_utils_init_mutex);
 #endif
 
 	/* call other module init functions here... */
 }
 
 #if defined( NEED_COPY_HOSTENT )