Source-Changes-HG archive

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

[src/netbsd-6]: src/lib/libc/net Pull up following revision(s) (requested by ...



details:   https://anonhg.NetBSD.org/src/rev/4405401e4497
branches:  netbsd-6
changeset: 777029:4405401e4497
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Tue Nov 17 09:25:03 2015 +0000

description:
Pull up following revision(s) (requested by christos in ticket #1340):
        lib/libc/net/getnetnamadr.c: revision 1.43 via patch
        lib/libc/net/getnetnamadr.c: revision 1.44 via patch
put the state back after it is used.
PR/50367: Stefan Schaeckeler: Apply fix to obey RES_CHECKNAME to getnetbyaddr
and getnetbyname.

diffstat:

 lib/libc/net/getaddrinfo.c  |  26 +++++++++++++++-----------
 lib/libc/net/getnetnamadr.c |  23 +++++++++++++++--------
 2 files changed, 30 insertions(+), 19 deletions(-)

diffs (191 lines):

diff -r 0965003df8f3 -r 4405401e4497 lib/libc/net/getaddrinfo.c
--- a/lib/libc/net/getaddrinfo.c        Mon Nov 16 09:02:28 2015 +0000
+++ b/lib/libc/net/getaddrinfo.c        Tue Nov 17 09:25:03 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: getaddrinfo.c,v 1.96.4.2 2013/12/23 22:56:48 riz Exp $ */
+/*     $NetBSD: getaddrinfo.c,v 1.96.4.3 2015/11/17 09:28:05 bouyer 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.96.4.2 2013/12/23 22:56:48 riz Exp $");
+__RCSID("$NetBSD: getaddrinfo.c,v 1.96.4.3 2015/11/17 09:28:05 bouyer Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -214,8 +214,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 int _dns_getaddrinfo(void *, void *, va_list);
 static void _sethtent(FILE **);
@@ -1102,9 +1102,12 @@
 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;
@@ -1124,6 +1127,7 @@
        _DIAGASSERT(answer != NULL);
        _DIAGASSERT(qname != NULL);
        _DIAGASSERT(pai != NULL);
+       _DIAGASSERT(res != NULL);
 
        memset(&sentinel, 0, sizeof(sentinel));
        cur = &sentinel;
@@ -1153,7 +1157,7 @@
                return (NULL);
        }
        n = dn_expand(answer->buf, eom, cp, bp, ep - bp);
-       if ((n < 0) || !(*name_ok)(bp)) {
+       if ((n < 0) || !maybe_ok(res, bp, name_ok)) {
                h_errno = NO_RECOVERY;
                return (NULL);
        }
@@ -1177,7 +1181,7 @@
        had_error = 0;
        while (ancount-- > 0 && cp < eom && !had_error) {
                n = dn_expand(answer->buf, eom, cp, bp, ep - bp);
-               if ((n < 0) || !(*name_ok)(bp)) {
+               if ((n < 0) || !maybe_ok(res, bp, name_ok)) {
                        had_error++;
                        continue;
                }
@@ -1196,7 +1200,7 @@
                if ((qtype == T_A || qtype == T_AAAA || qtype == T_ANY) &&
                    type == T_CNAME) {
                        n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);
-                       if ((n < 0) || !(*name_ok)(tbuf)) {
+                       if ((n < 0) || !maybe_ok(res, tbuf, name_ok)) {
                                had_error++;
                                continue;
                        }
@@ -1407,14 +1411,14 @@
                free(buf2);
                return NS_NOTFOUND;
        }
-       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 (q.next) {
-               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;
        }
diff -r 0965003df8f3 -r 4405401e4497 lib/libc/net/getnetnamadr.c
--- a/lib/libc/net/getnetnamadr.c       Mon Nov 16 09:02:28 2015 +0000
+++ b/lib/libc/net/getnetnamadr.c       Tue Nov 17 09:25:03 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: getnetnamadr.c,v 1.41 2008/05/18 22:36:15 lukem Exp $  */
+/*     $NetBSD: getnetnamadr.c,v 1.41.22.1 2015/11/17 09:25:03 bouyer Exp $    */
 
 /* Copyright (c) 1993 Carlos Leandro and Rui Salgueiro
  *     Dep. Matematica Universidade de Coimbra, Portugal, Europe
@@ -43,7 +43,7 @@
 static char sccsid_[] = "from getnetnamadr.c   1.4 (Coimbra) 93/06/03";
 static char rcsid[] = "Id: getnetnamadr.c,v 8.8 1997/06/01 20:34:37 vixie Exp ";
 #else
-__RCSID("$NetBSD: getnetnamadr.c,v 1.41 2008/05/18 22:36:15 lukem Exp $");
+__RCSID("$NetBSD: getnetnamadr.c,v 1.41.22.1 2015/11/17 09:25:03 bouyer Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -77,6 +77,12 @@
 __weak_alias(getnetbyname,_getnetbyname)
 #endif
 
+#define maybe_ok(res, nm, ok) (((res)->options & RES_NOCHECKNAME) != 0U || \
+                               (ok)(nm) != 0)
+#define maybe_hnok(res, hn) maybe_ok((res), (hn), res_hnok)
+#define maybe_dnok(res, dn) maybe_ok((res), (dn), res_dnok)
+
+
 extern int _net_stayopen;
 
 #define BYADDR 0
@@ -105,7 +111,7 @@
 static char *net_aliases[MAXALIASES];
 
 static int             parse_reversed_addr(const char *, in_addr_t *);
-static struct netent   *getnetanswer(querybuf *, int, int);
+static struct netent   *getnetanswer(res_state, querybuf *, int, int);
 static int             _files_getnetbyaddr(void *, void *, va_list);
 static int             _files_getnetbyname(void *, void *, va_list);
 static int             _dns_getnetbyaddr(void *, void *, va_list);
@@ -159,7 +165,7 @@
 }
 
 static struct netent *
-getnetanswer(querybuf *answer, int anslen, int net_i)
+getnetanswer(res_state res, querybuf *answer, int anslen, int net_i)
 {
        static char     n_name[MAXDNAME];
        static char     netbuf[PACKETSZ];
@@ -172,6 +178,7 @@
        char            *in, *bp, **ap, *ep;
 
        _DIAGASSERT(answer != NULL);
+       _DIAGASSERT(res != NULL);
 
        /*
         * find first satisfactory answer
@@ -216,7 +223,7 @@
        n_name[0] = '\0';
        while (--ancount >= 0 && cp < eom) {
                n = dn_expand(answer->buf, eom, cp, bp, ep - bp);
-               if ((n < 0) || !res_dnok(bp))
+               if ((n < 0) || !maybe_dnok(res, bp))
                        break;
                cp += n;
                (void)strlcpy(n_name, bp, sizeof(n_name));
@@ -226,7 +233,7 @@
                GETSHORT(n, cp);
                if (class == C_IN && type == T_PTR) {
                        n = dn_expand(answer->buf, eom, cp, bp, ep - bp);
-                       if ((n < 0) || !res_hnok(bp)) {
+                       if ((n < 0) || !maybe_hnok(res, bp)) {
                                cp += n;
                                return NULL;
                        }
@@ -357,8 +364,8 @@
                __res_put_state(res);
                return NS_NOTFOUND;
        }
+       np = getnetanswer(res, buf, anslen, BYADDR);
        __res_put_state(res);
-       np = getnetanswer(buf, anslen, BYADDR);
        free(buf);
        if (np) {
                /* maybe net should be unsigned? */
@@ -469,8 +476,8 @@
                __res_put_state(res);
                return NS_NOTFOUND;
        }
+       np = getnetanswer(res, buf, anslen, BYNAME);
        __res_put_state(res);
-       np = getnetanswer(buf, anslen, BYNAME);
        free(buf);
 
        if (np != NULL) {



Home | Main Index | Thread Index | Old Index