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.
This commit is contained in:
Mark Andrews
2001-11-01 03:55:57 +00:00
parent d91d025def
commit 11931cc68d
2 changed files with 27 additions and 13 deletions

View File

@@ -1,3 +1,9 @@
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.
1089. [func] libbind: inet_{cidr,net}_{pton,ntop}() now have IPv6
support.

View 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.6 2001/11/01 03:55:57 marka 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. */