mirror of
https://git.openldap.org/openldap/openldap.git
synced 2024-12-21 03:10:25 +08:00
ITS#2221: getaddrinfo(3) not thread-safe on some platforms (namely
due to res_() routines). Change all res_() dependent routines to share same mutex.
This commit is contained in:
parent
416aeb9347
commit
9ba95dd027
@ -315,9 +315,7 @@ struct ldap {
|
|||||||
#define LDAP_VALID(ld) ( (ld)->ld_valid == LDAP_VALID_SESSION )
|
#define LDAP_VALID(ld) ( (ld)->ld_valid == LDAP_VALID_SESSION )
|
||||||
|
|
||||||
#ifdef LDAP_R_COMPILE
|
#ifdef LDAP_R_COMPILE
|
||||||
#ifdef HAVE_RES_QUERY
|
|
||||||
LDAP_V ( ldap_pvt_thread_mutex_t ) ldap_int_resolv_mutex;
|
LDAP_V ( ldap_pvt_thread_mutex_t ) ldap_int_resolv_mutex;
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_CYRUS_SASL
|
#ifdef HAVE_CYRUS_SASL
|
||||||
LDAP_V( ldap_pvt_thread_mutex_t ) ldap_int_sasl_mutex;
|
LDAP_V( ldap_pvt_thread_mutex_t ) ldap_int_sasl_mutex;
|
||||||
|
@ -357,7 +357,19 @@ ldap_connect_to_host(LDAP *ld, Sockbuf *sb,
|
|||||||
hints.ai_socktype = socktype;
|
hints.ai_socktype = socktype;
|
||||||
|
|
||||||
snprintf(serv, sizeof serv, "%d", port );
|
snprintf(serv, sizeof serv, "%d", port );
|
||||||
if ( ( err = getaddrinfo(host, serv, &hints, &res) ) ) {
|
|
||||||
|
#ifdef LDAP_R_COMPILE
|
||||||
|
/* most getaddrinfo(3) use non-threadsafe resolver libraries */
|
||||||
|
ldap_pvt_thread_mutex_lock(&ldap_int_resolv_mutex);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
err = getaddrinfo( host, serv, &hints, &res );
|
||||||
|
|
||||||
|
#ifdef LDAP_R_COMPILE
|
||||||
|
ldap_pvt_thread_mutex_unlock(&ldap_int_resolv_mutex);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if ( err != 0 ) {
|
||||||
osip_debug(ld, "ldap_connect_to_host: getaddrinfo failed: %s\n",
|
osip_debug(ld, "ldap_connect_to_host: getaddrinfo failed: %s\n",
|
||||||
AC_GAI_STRERROR(err), 0, 0);
|
AC_GAI_STRERROR(err), 0, 0);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -59,9 +59,6 @@
|
|||||||
# ifndef USE_CTIME_R
|
# ifndef USE_CTIME_R
|
||||||
static ldap_pvt_thread_mutex_t ldap_int_ctime_mutex;
|
static ldap_pvt_thread_mutex_t ldap_int_ctime_mutex;
|
||||||
# endif
|
# endif
|
||||||
# if !defined( HAVE_GETHOSTBYNAME_R ) || !defined( HAVE_GETHOSTBYADDR_R )
|
|
||||||
static ldap_pvt_thread_mutex_t ldap_int_gethostby_mutex;
|
|
||||||
# endif
|
|
||||||
# ifdef HAVE_RES_QUERY
|
# ifdef HAVE_RES_QUERY
|
||||||
ldap_pvt_thread_mutex_t ldap_int_resolv_mutex;
|
ldap_pvt_thread_mutex_t ldap_int_resolv_mutex;
|
||||||
# endif
|
# endif
|
||||||
@ -148,7 +145,7 @@ int ldap_pvt_gethostbyname_a(
|
|||||||
int retval;
|
int retval;
|
||||||
*buf = NULL;
|
*buf = NULL;
|
||||||
|
|
||||||
ldap_pvt_thread_mutex_lock( &ldap_int_gethostby_mutex );
|
ldap_pvt_thread_mutex_lock( &ldap_int_resolv_mutex );
|
||||||
|
|
||||||
he = gethostbyname( name );
|
he = gethostbyname( name );
|
||||||
|
|
||||||
@ -163,7 +160,7 @@ int ldap_pvt_gethostbyname_a(
|
|||||||
retval = 0;
|
retval = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ldap_pvt_thread_mutex_unlock( &ldap_int_gethostby_mutex );
|
ldap_pvt_thread_mutex_unlock( &ldap_int_resolv_mutex );
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
#else
|
#else
|
||||||
@ -229,7 +226,7 @@ int ldap_pvt_gethostbyaddr_a(
|
|||||||
int retval;
|
int retval;
|
||||||
*buf = NULL;
|
*buf = NULL;
|
||||||
|
|
||||||
ldap_pvt_thread_mutex_lock( &ldap_int_gethostby_mutex );
|
ldap_pvt_thread_mutex_lock( &ldap_int_resolv_mutex );
|
||||||
|
|
||||||
he = gethostbyaddr( addr, len, type );
|
he = gethostbyaddr( addr, len, type );
|
||||||
|
|
||||||
@ -244,7 +241,7 @@ int ldap_pvt_gethostbyaddr_a(
|
|||||||
retval = 0;
|
retval = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ldap_pvt_thread_mutex_unlock( &ldap_int_gethostby_mutex );
|
ldap_pvt_thread_mutex_unlock( &ldap_int_resolv_mutex );
|
||||||
|
|
||||||
return retval;
|
return retval;
|
||||||
#else /* gethostbyaddr() */
|
#else /* gethostbyaddr() */
|
||||||
@ -274,10 +271,6 @@ void ldap_int_utils_init( void )
|
|||||||
ldap_pvt_thread_mutex_init( &ldap_int_ctime_mutex );
|
ldap_pvt_thread_mutex_init( &ldap_int_ctime_mutex );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined( HAVE_GETHOSTBYNAME_R ) || !defined( HAVE_GETHOSTBYADDR_R )
|
|
||||||
ldap_pvt_thread_mutex_init( &ldap_int_gethostby_mutex );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_RES_QUERY
|
#ifdef HAVE_RES_QUERY
|
||||||
ldap_pvt_thread_mutex_init( &ldap_int_resolv_mutex );
|
ldap_pvt_thread_mutex_init( &ldap_int_resolv_mutex );
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user