mirror of git://sourceware.org/git/glibc.git
[BZ #2499]
* resolv/nss_dns/dns-canon.c (_nss_dns_getcanonname_r): Avoid possibly unaligned memory accesses.
This commit is contained in:
parent
bce1646770
commit
acb98cb57d
|
|
@ -1,5 +1,9 @@
|
||||||
2006-05-06 Ulrich Drepper <drepper@redhat.com>
|
2006-05-06 Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
|
[BZ #2499]
|
||||||
|
* resolv/nss_dns/dns-canon.c (_nss_dns_getcanonname_r): Avoid
|
||||||
|
possibly unaligned memory accesses.
|
||||||
|
|
||||||
* include/arpa/nameser.h: Also optimize NS_PUT16 and NS_PUT32.
|
* include/arpa/nameser.h: Also optimize NS_PUT16 and NS_PUT32.
|
||||||
* resolv/res_mkquery.c: Use NS_PUT16 and NS_PUT32 instead of __putshort
|
* resolv/res_mkquery.c: Use NS_PUT16 and NS_PUT32 instead of __putshort
|
||||||
and __putlong respectively. Correct buffer overflow check for
|
and __putlong respectively. Correct buffer overflow check for
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 2004 Free Software Foundation, Inc.
|
/* Copyright (C) 2004, 2006 Free Software Foundation, Inc.
|
||||||
This file is part of the GNU C Library.
|
This file is part of the GNU C Library.
|
||||||
Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
|
Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
|
||||||
|
|
||||||
|
|
@ -40,6 +40,10 @@ typedef union querybuf
|
||||||
} querybuf;
|
} querybuf;
|
||||||
|
|
||||||
|
|
||||||
|
static const short int qtypes[] = { ns_t_a, ns_t_aaaa };
|
||||||
|
#define nqtypes (sizeof (qtypes) / sizeof (qtypes[0]))
|
||||||
|
|
||||||
|
|
||||||
enum nss_status
|
enum nss_status
|
||||||
_nss_dns_getcanonname_r (const char *name, char *buffer, size_t buflen,
|
_nss_dns_getcanonname_r (const char *name, char *buffer, size_t buflen,
|
||||||
char **result,int *errnop, int *h_errnop)
|
char **result,int *errnop, int *h_errnop)
|
||||||
|
|
@ -53,8 +57,6 @@ _nss_dns_getcanonname_r (const char *name, char *buffer, size_t buflen,
|
||||||
unsigned char *ptr;
|
unsigned char *ptr;
|
||||||
} ansp = { .ptr = buf };
|
} ansp = { .ptr = buf };
|
||||||
enum nss_status status = NSS_STATUS_UNAVAIL;
|
enum nss_status status = NSS_STATUS_UNAVAIL;
|
||||||
int qtypes[] = { ns_t_a, ns_t_aaaa };
|
|
||||||
#define nqtypes (sizeof (qtypes) / sizeof (qtypes[0]))
|
|
||||||
|
|
||||||
for (int i = 0; i < nqtypes; ++i)
|
for (int i = 0; i < nqtypes; ++i)
|
||||||
{
|
{
|
||||||
|
|
@ -101,7 +103,8 @@ _nss_dns_getcanonname_r (const char *name, char *buffer, size_t buflen,
|
||||||
ptr += s;
|
ptr += s;
|
||||||
|
|
||||||
/* Check whether type and class match. */
|
/* Check whether type and class match. */
|
||||||
unsigned int type = ntohs (*(uint16_t *) ptr);
|
uint_fast16_t type;
|
||||||
|
NS_GET16 (type, ptr);
|
||||||
if (type == qtypes[i])
|
if (type == qtypes[i])
|
||||||
{
|
{
|
||||||
/* We found the record. */
|
/* We found the record. */
|
||||||
|
|
@ -130,15 +133,14 @@ _nss_dns_getcanonname_r (const char *name, char *buffer, size_t buflen,
|
||||||
if (type != ns_t_cname)
|
if (type != ns_t_cname)
|
||||||
goto unavail;
|
goto unavail;
|
||||||
|
|
||||||
ptr += sizeof (uint16_t);
|
if (ns_get16 (ptr) != ns_c_in)
|
||||||
if (*(uint16_t *) ptr != htons (ns_c_in))
|
|
||||||
goto unavail;
|
goto unavail;
|
||||||
|
|
||||||
/* Also skip over the TTL. */
|
/* Also skip over the TTL. */
|
||||||
ptr += sizeof (uint16_t) + sizeof (uint32_t);
|
ptr += sizeof (uint16_t) + sizeof (uint32_t);
|
||||||
|
|
||||||
/* Skip over the data length and data. */
|
/* Skip over the data length and data. */
|
||||||
ptr += sizeof (uint16_t) + ntohs (*(uint16_t *) ptr);
|
ptr += sizeof (uint16_t) + ns_get16 (ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue