mirror of
https://github.com/isc-projects/bind9.git
synced 2026-04-29 09:59:08 -04:00
pullup:
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:
parent
6c87ddb75d
commit
a3a89d7c36
2 changed files with 27 additions and 13 deletions
6
CHANGES
6
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.
|
||||
|
|
|
|||
|
|
@ -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. */
|
||||
|
|
|
|||
Loading…
Reference in a new issue