Subject: Re: getaddrinfo() vs. JVM
To: Charles M. Hannum <abuse@spamalicious.com>
From: Love <lha@stacken.kth.se>
List: tech-userlevel
Date: 01/09/2005 17:39:01
--=-=-=


"Charles M. Hannum" <abuse@spamalicious.com> writes:

>> 2) Put a mutex around getservbyname() and/or getaddrinfo().  Is there a way
>> to do this in libc that will work both with and without libpthread?
>
> I've done this.  See the following patches.

Doesn't your patch just move the problem to possibly later ? Its a very
small window, but its still there.

Love


Index: getaddrinfo.c
===================================================================
RCS file: /sources/netbsd/NetBSD-cvs/src/lib/libc/net/getaddrinfo.c,v
retrieving revision 1.72
diff -u -u -w -r1.72 getaddrinfo.c
--- getaddrinfo.c	27 May 2004 18:40:07 -0000	1.72
+++ getaddrinfo.c	9 Jan 2005 16:31:44 -0000
@@ -901,7 +901,6 @@
 get_port(struct addrinfo *ai, const char *servname, int matchonly)
 {
 	const char *proto;
-	struct servent *sp;
 	int port;
 	int allownumeric;
 
@@ -942,6 +941,9 @@
 			return EAI_SERVICE;
 		port = htons(port);
 	} else {
+		struct servent_data serv_data;
+		struct servent *sp, s;
+
 		if (ai->ai_flags & AI_NUMERICSERV)
 			return EAI_NONAME;
 
@@ -957,7 +959,11 @@
 			break;
 		}
 
-		if ((sp = getservbyname(servname, proto)) == NULL)
+		memset(&serv_data, 0, sizeof(serv_data));
+		setservent_r(0, &serv_data);
+
+		sp = getservbyname_r(servname, proto, &s, &serv_data);
+		if (sp == NULL)
 			return EAI_SERVICE;
 		port = sp->s_port;
 	}

--=-=-=
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (NetBSD)

iQIVAwUAQeFeJxZyDLTSep3UAQJn4w/+JdNn+G3TuGyalc0R6NDS6zJR0ou3DZKR
DVRazbYWl0wJ3rFv8LDxv8E2f8jv3Y2C/3D4VfTJ3vI1nLFVExK3sH5B9na/sJFZ
LoSovRLWVUij73qrlC8V+gD9umDVmCn5UUhqCSHntwE02zTElvtB0msdOY3cOi8N
83OED4VxqIFg+zU0rdlvn0QRvp1Bot11R2I3SG28xwZwJzOZfyfABkOXcMCwl6ld
8KAIcXl2WV7YqkcUpFFkMxoG7SKQ/U5xkLDFX90SRrMwPJ9pN+1EGFC5fi3HOBOW
69GwnQWhgxzX6mM5fjdk3QQiCTYhMugxv1ygZwMzJoStXJ/nx3m6TlTGNWtz7jBX
lhHLK1YVmKJyG6vSmaQL9/kNxoaqKrGEDMU+eCXbqgitYiDreBXK/Omf7qvLquGa
8Q68ikuk7RZ761YU/mVVzsCUgF0xaRgisfkvn8Vb5jEdPd6M6gpcl4QXNaOTx/7l
gOQr++3654WgHIsSHWw/4wf5GLVW6JYjYvlegTdyiXLh4clnYlJ2EwGOaHAhnnIM
gCvW0qGKWC58f79/gQVVGnAZ4jgy0qTrpRiqEZT2QJgyOXAb0uVclFT1kFcRr8/F
oRwYgzfXVk/vffpjZVGdr90RLcXIkUaNuZB7WOUC03KI+Ux4GnEF80IQRZxR1p5o
xTAe/QhSgxY=
=Mc0U
-----END PGP SIGNATURE-----
--=-=-=--