Module Name:    src
Committed By:   riz
Date:           Mon Dec 23 23:12:44 UTC 2013

Modified Files:
        src/lib/libc/net [netbsd-5]: getaddrinfo.c gethnamaddr.c

Log Message:
Apply patch (requested by bad in ticket #1887):

src/lib/libc/net/getaddrinfo.c r1.106:
this is supposed to be re-entrant, call don't call __hostalias that uses
a static buffer.

src/lib/libc/net/gethnamaddr.c r1.85:
- don't clobber hp in the RES_USE_INET6 case
- increment naddrs in the yp case
- don't use __hostalias(), it is not thread-safe.

This should finish addressing PR lib/46454


To generate a diff of this commit:
cvs rdiff -u -r1.91.6.1 -r1.91.6.2 src/lib/libc/net/getaddrinfo.c
cvs rdiff -u -r1.73.18.2 -r1.73.18.3 src/lib/libc/net/gethnamaddr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/net/getaddrinfo.c
diff -u src/lib/libc/net/getaddrinfo.c:1.91.6.1 src/lib/libc/net/getaddrinfo.c:1.91.6.2
--- src/lib/libc/net/getaddrinfo.c:1.91.6.1	Mon Jan 26 00:27:34 2009
+++ src/lib/libc/net/getaddrinfo.c	Mon Dec 23 23:12:44 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: getaddrinfo.c,v 1.91.6.1 2009/01/26 00:27:34 snj Exp $	*/
+/*	$NetBSD: getaddrinfo.c,v 1.91.6.2 2013/12/23 23:12:44 riz Exp $	*/
 /*	$KAME: getaddrinfo.c,v 1.29 2000/08/31 17:26:57 itojun Exp $	*/
 
 /*
@@ -55,7 +55,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: getaddrinfo.c,v 1.91.6.1 2009/01/26 00:27:34 snj Exp $");
+__RCSID("$NetBSD: getaddrinfo.c,v 1.91.6.2 2013/12/23 23:12:44 riz Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -1764,6 +1764,7 @@ res_searchN(const char *name, struct res
 	const char *cp, * const *domain;
 	HEADER *hp;
 	u_int dots;
+	char buf[MAXHOSTNAMELEN];
 	int trailing_dot, ret, saved_herrno;
 	int got_nodata = 0, got_servfail = 0, tried_as_is = 0;
 
@@ -1784,7 +1785,7 @@ res_searchN(const char *name, struct res
 	/*
 	 * if there aren't any dots, it could be a user-level alias
 	 */
-	if (!dots && (cp = __hostalias(name)) != NULL) {
+	if (!dots && (cp = res_hostalias(res, name, buf, sizeof(buf))) != NULL) {
 		ret = res_queryN(cp, target, res);
 		return ret;
 	}

Index: src/lib/libc/net/gethnamaddr.c
diff -u src/lib/libc/net/gethnamaddr.c:1.73.18.2 src/lib/libc/net/gethnamaddr.c:1.73.18.3
--- src/lib/libc/net/gethnamaddr.c:1.73.18.2	Thu Dec 19 08:11:45 2013
+++ src/lib/libc/net/gethnamaddr.c	Mon Dec 23 23:12:44 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: gethnamaddr.c,v 1.73.18.2 2013/12/19 08:11:45 bouyer Exp $	*/
+/*	$NetBSD: gethnamaddr.c,v 1.73.18.3 2013/12/23 23:12:44 riz Exp $	*/
 
 /*
  * ++Copyright++ 1985, 1988, 1993
@@ -57,7 +57,7 @@
 static char sccsid[] = "@(#)gethostnamadr.c	8.1 (Berkeley) 6/4/93";
 static char rcsid[] = "Id: gethnamaddr.c,v 8.21 1997/06/01 20:34:37 vixie Exp ";
 #else
-__RCSID("$NetBSD: gethnamaddr.c,v 1.73.18.2 2013/12/19 08:11:45 bouyer Exp $");
+__RCSID("$NetBSD: gethnamaddr.c,v 1.73.18.3 2013/12/23 23:12:44 riz Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -514,11 +514,11 @@ gethostbyname_r(const char *name, struct
 	_DIAGASSERT(name != NULL);
 
 	if (res->options & RES_USE_INET6) {
-		hp = gethostbyname_internal(name, AF_INET6, res, hp, buf,
-		    buflen, he);
-		if (hp) {
+		struct hostent *nhp = gethostbyname_internal(name, AF_INET6,
+		    res, hp, buf, buflen, he);
+		if (nhp) {
 			__res_put_state(res);
-			return hp;
+			return nhp;
 		}
 	}
 	hp = gethostbyname_internal(name, AF_INET, res, hp, buf, buflen, he);
@@ -547,6 +547,7 @@ gethostbyname_internal(const char *name,
 {
 	const char *cp;
 	struct getnamaddr info;
+	char hbuf[MAXHOSTNAMELEN];
 	size_t size;
 	static const ns_dtab dtab[] = {
 		NS_FILES_CB(_hf_gethtbyname, NULL)
@@ -580,7 +581,8 @@ gethostbyname_internal(const char *name,
 	 * this is also done in res_nquery() since we are not the only
 	 * function that looks up host names.
 	 */
-	if (!strchr(name, '.') && (cp = __hostalias(name)))
+	if (!strchr(name, '.') && (cp = res_hostalias(res, name,
+	    hbuf, sizeof(hbuf))))
 		name = cp;
 
 	/*
@@ -1127,6 +1129,7 @@ nextline:
 		}
 		goto done;
 	}
+	naddrs++;
 
 	while (*cp == ' ' || *cp == '\t')
 		cp++;

Reply via email to