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 Pullup the following revisions, requested by...



details:   https://anonhg.NetBSD.org/src/rev/ee31c7587e9a
branches:  netbsd-6
changeset: 776529:ee31c7587e9a
user:      bouyer <bouyer%NetBSD.org@localhost>
date:      Wed Dec 18 22:39:32 2013 +0000

description:
Pullup the following revisions, requested by bad in ticket 975:
        lib/libc/net/gethnamaddr.c                      1.79-1.81, 1.84
        lib/libc/net/getnameinfo.3                      1.37-1.40
        lib/libc/net/getnameinfo.c                      1.51, 1.52, 1.54
        lib/libc/net/hostent.h                          1.1, 1.2
        lib/libc/net/sethostent.c                       1.17-1.19

Make getnameinfo(3) re-entrant (ahem __ypdomain).
Add not advertised reentrant functions: {get,set,end}hostent_r,
gethostbyname{,2}_r, gethostbyaddr_r. Make getnameinfo(3) use
gethostbyaddr_r(3).
Implement no-check-names.

diffstat:

 lib/libc/net/gethnamaddr.c |  904 +++++++++++++++++++-------------------------
 lib/libc/net/getnameinfo.3 |   26 +-
 lib/libc/net/getnameinfo.c |   89 +--
 lib/libc/net/hostent.h     |  106 +++++
 lib/libc/net/sethostent.c  |  227 ++++++++++-
 5 files changed, 773 insertions(+), 579 deletions(-)

diffs (truncated from 2206 to 300 lines):

diff -r 04dcfc84b96a -r ee31c7587e9a lib/libc/net/gethnamaddr.c
--- a/lib/libc/net/gethnamaddr.c        Wed Dec 18 02:22:19 2013 +0000
+++ b/lib/libc/net/gethnamaddr.c        Wed Dec 18 22:39:32 2013 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gethnamaddr.c,v 1.77 2011/10/15 23:00:02 christos Exp $        */
+/*     $NetBSD: gethnamaddr.c,v 1.77.4.1 2013/12/18 22:39:32 bouyer 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.77 2011/10/15 23:00:02 christos Exp $");
+__RCSID("$NetBSD: gethnamaddr.c,v 1.77.4.1 2013/12/18 22:39:32 bouyer Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -95,41 +95,38 @@
 #include <rpcsvc/ypclnt.h>
 #endif
 
+#include "hostent.h"
+
 #if defined(_LIBC) && defined(__weak_alias)
 __weak_alias(gethostbyaddr,_gethostbyaddr)
 __weak_alias(gethostbyname,_gethostbyname)
 __weak_alias(gethostent,_gethostent)
 #endif
 
-#define        MAXALIASES      35
-#define        MAXADDRS        35
+#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)
+
 
 static const char AskedForGot[] =
-                         "gethostby*.getanswer: asked for \"%s\", got \"%s\"";
+    "gethostby*.getanswer: asked for \"%s\", got \"%s\"";
 
-static char *h_addr_ptrs[MAXADDRS + 1];
 
 #ifdef YP
 static char *__ypdomain;
 #endif
 
-static struct hostent host;
-static char *host_aliases[MAXALIASES];
-static char hostbuf[8*1024];
-static u_int32_t host_addr[16 / sizeof(u_int32_t)];    /* IPv4 or IPv6 */
-static FILE *hostf = NULL;
-static int stayopen = 0;
-
 #define        MAXPACKET       (64*1024)
 
 typedef union {
-    HEADER hdr;
-    u_char buf[MAXPACKET];
+       HEADER hdr;
+       u_char buf[MAXPACKET];
 } querybuf;
 
 typedef union {
-    int32_t al;
-    char ac;
+       int32_t al;
+       char ac;
 } align;
 
 #ifdef DEBUG
@@ -137,33 +134,21 @@
        __attribute__((__format__(__printf__, 1, 3)));
 #endif
 static struct hostent *getanswer(const querybuf *, int, const char *, int,
-    res_state);
+    res_state, struct hostent *, char *, size_t, int *);
 static void map_v4v6_address(const char *, char *);
 static void map_v4v6_hostent(struct hostent *, char **, char *);
 static void addrsort(char **, int, res_state);
 
-void _sethtent(int);
-void _endhtent(void);
-struct hostent *_gethtent(void);
-void ht_sethostent(int);
-void ht_endhostent(void);
-struct hostent *ht_gethostbyname(char *);
-struct hostent *ht_gethostbyaddr(const char *, int, int);
 void dns_service(void);
 #undef dn_skipname
 int dn_skipname(const u_char *, const u_char *);
-int _gethtbyaddr(void *, void *, va_list);
-int _gethtbyname(void *, void *, va_list);
-struct hostent *_gethtbyname2(const char *, int);
-int _dns_gethtbyaddr(void *, void *, va_list);
-int _dns_gethtbyname(void *, void *, va_list);
+
 #ifdef YP
-struct hostent *_yphostent(char *, int);
-int _yp_gethtbyaddr(void *, void *, va_list);
-int _yp_gethtbyname(void *, void *, va_list);
+static struct hostent *_yp_hostent(char *, int, struct getnamaddr *);
 #endif
 
-static struct hostent *gethostbyname_internal(const char *, int, res_state);
+static struct hostent *gethostbyname_internal(const char *, int, res_state,
+    struct hostent *, char *, size_t, int *);
 
 static const ns_src default_dns_files[] = {
        { NSSRC_FILES,  NS_SUCCESS },
@@ -212,17 +197,20 @@
 
 static struct hostent *
 getanswer(const querybuf *answer, int anslen, const char *qname, int qtype,
-    res_state res)
+    res_state res, struct hostent *hent, char *buf, size_t buflen, int *he)
 {
        const HEADER *hp;
        const u_char *cp;
        int n;
+       size_t qlen;
        const u_char *eom, *erdata;
        char *bp, **ap, **hap, *ep;
        int type, class, ancount, qdcount;
        int haveanswer, had_error;
        int toobig = 0;
        char tbuf[MAXDNAME];
+       char *aliases[MAXALIASES];
+       char *addr_ptrs[MAXADDRS];
        const char *tname;
        int (*name_ok)(const char *);
 
@@ -230,7 +218,7 @@
        _DIAGASSERT(qname != NULL);
 
        tname = qname;
-       host.h_name = NULL;
+       hent->h_name = NULL;
        eom = answer->buf + anslen;
        switch (qtype) {
        case T_A:
@@ -249,46 +237,40 @@
        hp = &answer->hdr;
        ancount = ntohs(hp->ancount);
        qdcount = ntohs(hp->qdcount);
-       bp = hostbuf;
-       ep = hostbuf + sizeof hostbuf;
+       bp = buf;
+       ep = buf + buflen;
        cp = answer->buf;
        BOUNDED_INCR(HFIXEDSZ);
-       if (qdcount != 1) {
-               h_errno = NO_RECOVERY;
-               return NULL;
-       }
-       n = dn_expand(answer->buf, eom, cp, bp, ep - bp);
-       if ((n < 0) || !(*name_ok)(bp)) {
-               h_errno = NO_RECOVERY;
-               return NULL;
-       }
+       if (qdcount != 1)
+               goto no_recovery;
+
+       n = dn_expand(answer->buf, eom, cp, bp, (int)(ep - bp));
+       if ((n < 0) || !maybe_ok(res, bp, name_ok))
+               goto no_recovery;
+
        BOUNDED_INCR(n + QFIXEDSZ);
        if (qtype == T_A || qtype == T_AAAA) {
                /* res_send() has already verified that the query name is the
                 * same as the one we sent; this just gets the expanded name
                 * (i.e., with the succeeding search-domain tacked on).
                 */
-               n = strlen(bp) + 1;             /* for the \0 */
-               if (n >= MAXHOSTNAMELEN) {
-                       h_errno = NO_RECOVERY;
-                       return NULL;
-               }
-               host.h_name = bp;
+               n = (int)strlen(bp) + 1;                /* for the \0 */
+               if (n >= MAXHOSTNAMELEN)
+                       goto no_recovery;
+               hent->h_name = bp;
                bp += n;
                /* The qname can be abbreviated, but h_name is now absolute. */
-               qname = host.h_name;
+               qname = hent->h_name;
        }
-       ap = host_aliases;
+       hent->h_aliases = ap = aliases;
+       hent->h_addr_list = hap = addr_ptrs;
        *ap = NULL;
-       host.h_aliases = host_aliases;
-       hap = h_addr_ptrs;
        *hap = NULL;
-       host.h_addr_list = h_addr_ptrs;
        haveanswer = 0;
        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)) {
+               n = dn_expand(answer->buf, eom, cp, bp, (int)(ep - bp));
+               if ((n < 0) || !maybe_ok(res, bp, name_ok)) {
                        had_error++;
                        continue;
                }
@@ -308,50 +290,48 @@
                        continue;               /* XXX - had_error++ ? */
                }
                if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME) {
-                       if (ap >= &host_aliases[MAXALIASES-1])
+                       if (ap >= &aliases[MAXALIASES-1])
                                continue;
-                       n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);
-                       if ((n < 0) || !(*name_ok)(tbuf)) {
+                       n = dn_expand(answer->buf, eom, cp, tbuf,
+                           (int)sizeof tbuf);
+                       if ((n < 0) || !maybe_ok(res, tbuf, name_ok)) {
                                had_error++;
                                continue;
                        }
                        cp += n;
-                       if (cp != erdata) {
-                               h_errno = NO_RECOVERY;
-                               return NULL;
-                       }
+                       if (cp != erdata)
+                               goto no_recovery;
                        /* Store alias. */
                        *ap++ = bp;
-                       n = strlen(bp) + 1;     /* for the \0 */
+                       n = (int)strlen(bp) + 1;        /* for the \0 */
                        if (n >= MAXHOSTNAMELEN) {
                                had_error++;
                                continue;
                        }
                        bp += n;
                        /* Get canonical name. */
-                       n = strlen(tbuf) + 1;   /* for the \0 */
+                       n = (int)strlen(tbuf) + 1;      /* for the \0 */
                        if (n > ep - bp || n >= MAXHOSTNAMELEN) {
                                had_error++;
                                continue;
                        }
                        strlcpy(bp, tbuf, (size_t)(ep - bp));
-                       host.h_name = bp;
+                       hent->h_name = bp;
                        bp += n;
                        continue;
                }
                if (qtype == T_PTR && type == T_CNAME) {
-                       n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);
-                       if (n < 0 || !res_dnok(tbuf)) {
+                       n = dn_expand(answer->buf, eom, cp, tbuf,
+                           (int)sizeof tbuf);
+                       if (n < 0 || !maybe_dnok(res, tbuf)) {
                                had_error++;
                                continue;
                        }
                        cp += n;
-                       if (cp != erdata) {
-                               h_errno = NO_RECOVERY;
-                               return NULL;
-                       }
+                       if (cp != erdata)
+                               goto no_recovery;
                        /* Get canonical name. */
-                       n = strlen(tbuf) + 1;   /* for the \0 */
+                       n = (int)strlen(tbuf) + 1;      /* for the \0 */
                        if (n > ep - bp || n >= MAXHOSTNAMELEN) {
                                had_error++;
                                continue;
@@ -378,25 +358,23 @@
                                cp += n;
                                continue;       /* XXX - had_error++ ? */
                        }
-                       n = dn_expand(answer->buf, eom, cp, bp, ep - bp);
-                       if ((n < 0) || !res_hnok(bp)) {
+                       n = dn_expand(answer->buf, eom, cp, bp, (int)(ep - bp));
+                       if ((n < 0) || !maybe_hnok(res, bp)) {
                                had_error++;
                                break;
                        }
 #if MULTI_PTRS_ARE_ALIASES
                        cp += n;
-                       if (cp != erdata) {
-                               h_errno = NO_RECOVERY;
-                               return NULL;
-                       }
+                       if (cp != erdata)
+                               goto no_recovery;
                        if (!haveanswer)
-                               host.h_name = bp;
-                       else if (ap < &host_aliases[MAXALIASES-1])
+                               hent->h_name = bp;
+                       else if (ap < &aliases[MAXALIASES-1])
                                *ap++ = bp;
                        else
                                n = -1;



Home | Main Index | Thread Index | Old Index