]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
pullup:
authorAndreas Gustafsson <source@isc.org>
Fri, 2 Nov 2001 20:35:28 +0000 (20:35 +0000)
committerAndreas Gustafsson <source@isc.org>
Fri, 2 Nov 2001 20:35:28 +0000 (20:35 +0000)
1090.   [bug]           libbind: dns_ho.c:add_hostent() was not returning
                        the amount of memory consumed resulting in garbage
                        address being returned.  Alignment calculations were
                        wasting space.  We wern't suppressing duplicate
                        addresses.

CHANGES
lib/bind/irs/dns_ho.c

diff --git a/CHANGES b/CHANGES
index 4ba429a5b06dcd160cc1737df367da7537313e61..7e4bdb6b3082327aaf80308bb572f9131ce0679e 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -6,6 +6,12 @@
 
 1101.  [bug]           Array bounds read error in lwres_gai_strerror.
 
+1090.  [bug]           libbind: dns_ho.c:add_hostent() was not returning
+                       the amount of memory consumed resulting in garbage
+                       address being returned.  Alignment calculations were   
+                       wasting space.  We weren't suppressing duplicate
+                       addresses.
+
 1088.  [port]          libbind: MPE/iX C.70 (incomplete)
 
 1086.  [port]          libbind: sunos: old sprintf.
index 3e596f0167190b9b9d35ec2024d5fb96412a9a79..a563ff746cd4fcf7d859078daa19278e6443b83a 100644 (file)
@@ -52,7 +52,7 @@
 /* BIND Id: gethnamaddr.c,v 8.15 1996/05/22 04:56:30 vixie Exp $ */
 
 #if defined(LIBC_SCCS) && !defined(lint)
-static const char rcsid[] = "$Id: dns_ho.c,v 1.5 2001/07/02 00:44:50 marka Exp $";
+static const char rcsid[] = "$Id: dns_ho.c,v 1.5.2.1 2001/11/02 20:35:28 gson Exp $";
 #endif /* LIBC_SCCS and not lint */
 
 /* Imports. */
@@ -1400,7 +1400,8 @@ gethostans(struct irs_ho *this,
                                buflen -= nn;
                        }
                        /* Ensure alignment. */
-                       bp += sizeof(align) - ((u_long)bp % sizeof(align));
+                       bp = (char *)(((u_long)bp + (sizeof(align) - 1)) &
+                                     ~(sizeof(align) - 1));
                        /* Avoid overflows. */
                        if (bp + n >= &pvt->hostbuf[sizeof pvt->hostbuf]) {
                                had_error++;
@@ -1421,6 +1422,8 @@ gethostans(struct irs_ho *this,
                                                had_error++;
                                                break;
                                        }
+                                       if (m == 0)
+                                               continue;
                                        if (hap < &pvt->h_addr_ptrs[MAXADDRS-1])
                                                hap++;
 
@@ -1491,6 +1494,8 @@ add_hostent(struct pvt *pvt, char *bp, char **hap, struct addrinfo *ai)
 {
        int addrlen;
        char *addrp;
+       const char **tap;
+       char *obp = bp;
 
        switch(ai->ai_addr->sa_family) {
        case AF_INET6:
@@ -1505,26 +1510,26 @@ add_hostent(struct pvt *pvt, char *bp, char **hap, struct addrinfo *ai)
                return(-1);     /* abort? */
        }
 
-       bp += sizeof(align) - ((u_long)bp % sizeof(align));
+       /* Ensure alignment. */
+       bp = (char *)(((u_long)bp + (sizeof(align) - 1)) &
+                     ~(sizeof(align) - 1));
+       /* Avoid overflows. */
        if (bp + addrlen >= &pvt->hostbuf[sizeof pvt->hostbuf])
                return(-1);
        if (hap >= &pvt->h_addr_ptrs[MAXADDRS-1])
-               return(addrlen); /* fail, but not treat it as an error. */
-#if 0
+               return(0); /* fail, but not treat it as an error. */
+
        /* Suppress duplicates. */
        for (tap = (const char **)pvt->h_addr_ptrs;
             *tap != NULL;
             tap++)
-               if (memcmp(*tap, cp, n) == 0)
+               if (memcmp(*tap, addrp, addrlen) == 0)
                        break;
-       if (*tap != NULL) {
-               cp += n;
-               continue;
-       }
-#endif
+       if (*tap != NULL)
+               return (0);
 
        memcpy(*hap = bp, addrp, addrlen);
-       return(addrlen);
+       return((bp + addrlen) - obp);
 }
 
 static void
@@ -1536,7 +1541,10 @@ map_v4v6_hostent(struct hostent *hp, char **bpp, int *lenp) {
        hp->h_addrtype = AF_INET6;
        hp->h_length = IN6ADDRSZ;
        for (ap = hp->h_addr_list; *ap; ap++) {
-               int i = sizeof(align) - ((u_long)*bpp % sizeof(align));
+               int i = (u_long)*bpp % sizeof(align);
+
+               if (i != 0)
+                       i = sizeof(align) - i;
 
                if (*lenp < (i + IN6ADDRSZ)) {
                        /* Out of memory.  Truncate address list here. */