File: getaddrinfo-is-threadsafe

package info (click to toggle)
openldap 2.6.10%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 31,080 kB
  • sloc: ansic: 328,961; sh: 51,256; cpp: 6,011; makefile: 3,320; sql: 1,714; perl: 455; python: 184; tcl: 45
file content (47 lines) | stat: -rw-r--r-- 1,852 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Author: Steve Langasek <vorlon@debian.org>

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.

Index: openldap/libraries/libldap/os-ip.c
===================================================================
--- openldap.orig/libraries/libldap/os-ip.c	2022-05-20 17:36:12.989246703 -0400
+++ openldap/libraries/libldap/os-ip.c	2022-05-20 17:36:12.989246703 -0400
@@ -645,13 +645,7 @@
 	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: openldap/libraries/libldap/util-int.c
===================================================================
--- openldap.orig/libraries/libldap/util-int.c	2022-05-20 17:36:12.989246703 -0400
+++ openldap/libraries/libldap/util-int.c	2022-05-20 17:36:12.989246703 -0400
@@ -559,9 +559,7 @@
 	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;