getaddrinfo-is-threadsafe
authorSteve Langasek <vorlon@debian.org>
Fri, 27 Aug 2021 16:42:31 +0000 (17:42 +0100)
committerRyan Tandy <ryan@nardis.ca>
Fri, 27 Aug 2021 16:42:31 +0000 (17:42 +0100)
OpenLDAP upstream conservatively assumes that certain resolver functions
(getaddrinfo, getnameinfo, res_query, dn_expand) are not re-entrant; but we
know that the glibc implementations of these functions are thread-safe, so
we should bypass the use of this mutex.  This fixes a locking problem when
an application uses libldap and libnss-ldap is also used for hosts
resolution.

Closes Debian bug #340601.

Not suitable for forwarding upstream; might be made suitable by adding a
configure-time check for glibc and disabling the mutex only on known
thread-safe implementations.

Gbp-Pq: Name getaddrinfo-is-threadsafe

libraries/libldap/os-ip.c
libraries/libldap/util-int.c

index 9d9242a2586f2f3c8c142e392999e6676f87cd9d..a641adf2264175073f55bc0320c9d74b927e36f6 100644 (file)
@@ -602,13 +602,7 @@ ldap_connect_to_host(LDAP *ld, Sockbuf *sb,
        hints.ai_socktype = socktype;
        snprintf(serv, sizeof serv, "%d", port );
 
-       /* most getaddrinfo(3) use non-threadsafe resolver libraries */
-       LDAP_MUTEX_LOCK(&ldap_int_resolv_mutex);
-
        err = getaddrinfo( host, serv, &hints, &res );
-
-       LDAP_MUTEX_UNLOCK(&ldap_int_resolv_mutex);
-
        if ( err != 0 ) {
                osip_debug(ld, "ldap_connect_to_host: getaddrinfo failed: %s\n",
                        AC_GAI_STRERROR(err), 0, 0);
index d4c0dfa1e3cd354a54715c7a7a81a5a55a656ace..87b8248643f7008f98b89567b7d6de0893caf30f 100644 (file)
@@ -534,9 +534,7 @@ int ldap_pvt_get_hname(
        int rc;
 #if defined( HAVE_GETNAMEINFO )
 
-       LDAP_MUTEX_LOCK( &ldap_int_resolv_mutex );
        rc = getnameinfo( sa, len, name, namelen, NULL, 0, 0 );
-       LDAP_MUTEX_UNLOCK( &ldap_int_resolv_mutex );
        if ( rc ) *err = (char *)AC_GAI_STRERROR( rc );
        return rc;