Module Name:    src
Committed By:   sborrill
Date:           Fri Jan 15 18:09:19 UTC 2016

Modified Files:
        src/lib/libc/net [netbsd-7-0]: getaddrinfo.c

Log Message:
Pull up to netbsd-7 (missing part of ticket #1012):
lib/libc/net/getaddrinfo.c      1.110


To generate a diff of this commit:
cvs rdiff -u -r1.106 -r1.106.6.1 src/lib/libc/net/getaddrinfo.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.106 src/lib/libc/net/getaddrinfo.c:1.106.6.1
--- src/lib/libc/net/getaddrinfo.c:1.106	Sun Dec 22 02:40:48 2013
+++ src/lib/libc/net/getaddrinfo.c	Fri Jan 15 18:09:19 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: getaddrinfo.c,v 1.106 2013/12/22 02:40:48 christos Exp $	*/
+/*	$NetBSD: getaddrinfo.c,v 1.106.6.1 2016/01/15 18:09:19 sborrill 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.106 2013/12/22 02:40:48 christos Exp $");
+__RCSID("$NetBSD: getaddrinfo.c,v 1.106.6.1 2016/01/15 18:09:19 sborrill Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -221,8 +221,8 @@ static int addrconfig(uint64_t *);
 static int ip6_str2scopeid(char *, struct sockaddr_in6 *, u_int32_t *);
 #endif
 
-static struct addrinfo *getanswer(const querybuf *, int, const char *, int,
-    const struct addrinfo *);
+static struct addrinfo *getanswer(res_state, const querybuf *, int,
+    const char *, int, const struct addrinfo *);
 static void aisort(struct addrinfo *s, res_state res);
 static struct addrinfo * _dns_query(struct res_target *,
     const struct addrinfo *, res_state, int);
@@ -1157,9 +1157,11 @@ ip6_str2scopeid(char *scope, struct sock
 static const char AskedForGot[] =
 	"gethostby*.getanswer: asked for \"%s\", got \"%s\"";
 
+#define maybe_ok(res, nm, ok) (((res)->options & RES_NOCHECKNAME) != 0U || \
+                               (ok)(nm) != 0)
 static struct addrinfo *
-getanswer(const querybuf *answer, int anslen, const char *qname, int qtype,
-    const struct addrinfo *pai)
+getanswer(res_state res, const querybuf *answer, int anslen, const char *qname,
+    int qtype, const struct addrinfo *pai)
 {
 	struct addrinfo sentinel, *cur;
 	struct addrinfo ai, *aip;
@@ -1181,6 +1183,7 @@ getanswer(const querybuf *answer, int an
 	_DIAGASSERT(answer != NULL);
 	_DIAGASSERT(qname != NULL);
 	_DIAGASSERT(pai != NULL);
+	_DIAGASSERT(res != NULL);
 
 	memset(&sentinel, 0, sizeof(sentinel));
 	cur = &sentinel;
@@ -1213,7 +1216,7 @@ getanswer(const querybuf *answer, int an
 		return (NULL);
 	}
 	n = dn_expand(answer->buf, eom, cp, bp, (int)(ep - bp));
-	if ((n < 0) || !(*name_ok)(bp)) {
+	if ((n < 0) || !maybe_ok(res, bp, name_ok)) {
 		h_errno = NO_RECOVERY;
 		return (NULL);
 	}
@@ -1238,7 +1241,7 @@ getanswer(const querybuf *answer, int an
 	srvlist = NULL;
 	while (ancount-- > 0 && cp < eom && !had_error) {
 		n = dn_expand(answer->buf, eom, cp, bp, (int)(ep - bp));
-		if ((n < 0) || !(*name_ok)(bp)) {
+		if ((n < 0) || !maybe_ok(res, bp, name_ok)) {
 			had_error++;
 			continue;
 		}
@@ -1257,7 +1260,7 @@ getanswer(const querybuf *answer, int an
 		if ((qtype == T_A || qtype == T_AAAA || qtype == T_ANY) &&
 		    type == T_CNAME) {
 			n = dn_expand(answer->buf, eom, cp, tbuf, (int)sizeof tbuf);
-			if ((n < 0) || !(*name_ok)(tbuf)) {
+			if ((n < 0) || !maybe_ok(res, tbuf, name_ok)) {
 				had_error++;
 				continue;
 			}
@@ -1348,7 +1351,7 @@ getanswer(const querybuf *answer, int an
 			cp += INT16SZ;
 			n = dn_expand(answer->buf, eom, cp, tbuf,
 			    (int)sizeof(tbuf));
-			if ((n < 0) || !res_hnok(tbuf)) {
+			if ((n < 0) || !maybe_ok(res, tbuf, res_hnok)) {
 				had_error++;
 				continue;
 			}
@@ -1394,7 +1397,6 @@ getanswer(const querybuf *answer, int an
 	}
 
 	if (srvlist) {
-		res_state res;
 		/*
 		 * Check for explicit rejection.
 		 */
@@ -1403,16 +1405,6 @@ getanswer(const querybuf *answer, int an
 			h_errno = HOST_NOT_FOUND;
 			return NULL;
 		}
-		res = __res_get_state();
-		if (res == NULL) {
-			while (srvlist != NULL) {
-				srv = srvlist;
-				srvlist = srvlist->next;
-				free(srv);
-			}
-			h_errno = NETDB_INTERNAL;
-			return NULL;
-		}
 
 		while (srvlist) {
 			struct res_target q, q2;
@@ -1447,7 +1439,6 @@ getanswer(const querybuf *answer, int an
 			}
 			free(srv);
 		}
-		__res_put_state(res);
 	}
 	if (haveanswer) {
 		if (!sentinel.ai_next->ai_canonname)
@@ -1536,14 +1527,14 @@ _dns_query(struct res_target *q, const s
 			goto out;
 	}
 
-	ai = getanswer(buf, q->n, q->name, q->qtype, pai);
+	ai = getanswer(res, buf, q->n, q->name, q->qtype, pai);
 	if (ai) {
 		cur->ai_next = ai;
 		while (cur && cur->ai_next)
 			cur = cur->ai_next;
 	}
 	if (q2) {
-		ai = getanswer(buf2, q2->n, q2->name, q2->qtype, pai);
+		ai = getanswer(res, buf2, q2->n, q2->name, q2->qtype, pai);
 		if (ai)
 			cur->ai_next = ai;
  	}

Reply via email to