getaddrinfo-is-threadsafe
authorSteve Langasek <vorlon@debian.org>
Fri, 26 Apr 2024 23:09:29 +0000 (16:09 -0700)
committerRyan Tandy <ryan@nardis.ca>
Fri, 26 Apr 2024 23:09:29 +0000 (16:09 -0700)
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 a84735e7afead4525b1800feb90fedd7619e009b..ba0354bc8488f147ba57c0588fae8848de610236 100644 (file)
@@ -645,13 +645,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 ) {
                Debug1(LDAP_DEBUG_TRACE,
                        "ldap_connect_to_host: getaddrinfo failed: %s\n",
index 7cab9ea3e566afa4811ce1caf53b9d27d1ddff9b..6375ecfce9901bc43b462d3299e5a30b82770675 100644 (file)
@@ -487,9 +487,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;