Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/net PR/50367: Stefan Schaeckeler: libc resolver lib...



details:   https://anonhg.NetBSD.org/src/rev/f545905e3c59
branches:  trunk
changeset: 341215:f545905e3c59
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Oct 26 14:48:04 2015 +0000

description:
PR/50367: Stefan Schaeckeler: libc resolver library does not resolve host
names with underscores ("_"). According to resolv.conf(5) RES_NOCHECKNAME
is on by default; well, it is and gethostbyname(3) obeys it
(gethnamaddr.c:maybe_ok), but getaddrinfo(3) up till this commit not.
XXX: pullup-7, pullup-6

diffstat:

 lib/libc/net/getaddrinfo.c |  39 +++++++++++++++------------------------
 1 files changed, 15 insertions(+), 24 deletions(-)

diffs (137 lines):

diff -r 218eabc55964 -r f545905e3c59 lib/libc/net/getaddrinfo.c
--- a/lib/libc/net/getaddrinfo.c        Mon Oct 26 11:44:30 2015 +0000
+++ b/lib/libc/net/getaddrinfo.c        Mon Oct 26 14:48:04 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: getaddrinfo.c,v 1.109 2015/09/10 14:05:06 christos Exp $       */
+/*     $NetBSD: getaddrinfo.c,v 1.110 2015/10/26 14:48:04 christos 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.109 2015/09/10 14:05:06 christos Exp $");
+__RCSID("$NetBSD: getaddrinfo.c,v 1.110 2015/10/26 14:48:04 christos Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #ifndef RUMP_ACTION
@@ -226,8 +226,8 @@
 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);
@@ -1162,9 +1162,11 @@
 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;
@@ -1186,6 +1188,7 @@
        _DIAGASSERT(answer != NULL);
        _DIAGASSERT(qname != NULL);
        _DIAGASSERT(pai != NULL);
+       _DIAGASSERT(res != NULL);
 
        memset(&sentinel, 0, sizeof(sentinel));
        cur = &sentinel;
@@ -1218,7 +1221,7 @@
                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);
        }
@@ -1243,7 +1246,7 @@
        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;
                }
@@ -1262,7 +1265,7 @@
                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;
                        }
@@ -1353,7 +1356,7 @@
                        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;
                        }
@@ -1399,7 +1402,6 @@
        }
 
        if (srvlist) {
-               res_state res;
                /*
                 * Check for explicit rejection.
                 */
@@ -1408,16 +1410,6 @@
                        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;
@@ -1452,7 +1444,6 @@
                        }
                        free(srv);
                }
-               __res_put_state(res);
        }
        if (haveanswer) {
                if (!sentinel.ai_next->ai_canonname)
@@ -1541,14 +1532,14 @@
                        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;
        }



Home | Main Index | Thread Index | Old Index