]> git.sur5r.net Git - openldap/commitdiff
ITS#7270 Protect accesses to ldap_int_hostname with a mutex.
authorFrederik Deweerdt <frederik.deweerdt@gmail.com>
Fri, 11 May 2012 21:05:21 +0000 (14:05 -0700)
committerQuanah Gibson-Mount <quanah@openldap.org>
Wed, 30 May 2012 20:26:48 +0000 (13:26 -0700)
Not protecting the accesses to ldap_int_hostname could lead to a double
free.

libraries/libldap/init.c
libraries/libldap/ldap-int.h
libraries/libldap/util-int.c

index 48e0e08b814058f359a99fd9380425ec2ad4e9de..7ac377d65631eca42b9a60014f3b9405a8ce4d25 100644 (file)
@@ -636,6 +636,7 @@ void ldap_int_initialize( struct ldapoptions *gopts, int *dbglvl )
 
 #if defined(HAVE_TLS) || defined(HAVE_CYRUS_SASL)
        {
+               LDAP_MUTEX_LOCK( &ldap_int_hostname_mutex );
                char    *name = ldap_int_hostname;
 
                ldap_int_hostname = ldap_pvt_get_fqdn( name );
@@ -643,6 +644,7 @@ void ldap_int_initialize( struct ldapoptions *gopts, int *dbglvl )
                if ( name != NULL && name != ldap_int_hostname ) {
                        LDAP_FREE( name );
                }
+               LDAP_MUTEX_UNLOCK( &ldap_int_hostname_mutex );
        }
 #endif
 
index 1ef15ad21590c4d5f13dc1a1cae2c59aa5e07078..7aca22236dd40110ae080252f3ad04f574106ee1 100644 (file)
@@ -482,6 +482,7 @@ struct ldap {
 
 #ifdef LDAP_R_COMPILE
 LDAP_V ( ldap_pvt_thread_mutex_t ) ldap_int_resolv_mutex;
+LDAP_V ( ldap_pvt_thread_mutex_t ) ldap_int_hostname_mutex;
 
 #ifdef HAVE_CYRUS_SASL
 LDAP_V( ldap_pvt_thread_mutex_t ) ldap_int_sasl_mutex;
index 85f13fcedd72d874bf11f798e329bd8b2b1d1aee..f451cc541c05fcecb6711ac6ca245fc8c5441ee4 100644 (file)
@@ -58,6 +58,7 @@ extern int h_errno;
 #else
 # include <ldap_pvt_thread.h>
   ldap_pvt_thread_mutex_t ldap_int_resolv_mutex;
+  ldap_pvt_thread_mutex_t ldap_int_hostname_mutex;
 
 # if (defined( HAVE_CTIME_R ) || defined( HAVE_REENTRANT_FUNCTIONS)) \
         && defined( CTIME_R_NARGS )
@@ -603,6 +604,8 @@ void ldap_int_utils_init( void )
 #endif
        ldap_pvt_thread_mutex_init( &ldap_int_resolv_mutex );
 
+       ldap_pvt_thread_mutex_init( &ldap_int_hostname_mutex );
+
 #ifdef HAVE_CYRUS_SASL
        ldap_pvt_thread_mutex_init( &ldap_int_sasl_mutex );
 #endif