aboutsummaryrefslogtreecommitdiff
path: root/resolv/nss_dns
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2004-12-22 20:10:10 +0000
committerUlrich Drepper <drepper@redhat.com>2004-12-22 20:10:10 +0000
commita334319f6530564d22e775935d9c91663623a1b4 (patch)
treeb5877475619e4c938e98757d518bb1e9cbead751 /resolv/nss_dns
parent0ecb606cb6cf65de1d9fc8a919bceb4be476c602 (diff)
downloadglibc-a334319f6530564d22e775935d9c91663623a1b4.tar
glibc-a334319f6530564d22e775935d9c91663623a1b4.tar.gz
glibc-a334319f6530564d22e775935d9c91663623a1b4.tar.bz2
glibc-a334319f6530564d22e775935d9c91663623a1b4.zip
(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
Diffstat (limited to 'resolv/nss_dns')
-rw-r--r--resolv/nss_dns/dns-canon.c16
-rw-r--r--resolv/nss_dns/dns-host.c15
-rw-r--r--resolv/nss_dns/dns-network.c47
3 files changed, 28 insertions, 50 deletions
diff --git a/resolv/nss_dns/dns-canon.c b/resolv/nss_dns/dns-canon.c
index fca6cd8997..91708df51f 100644
--- a/resolv/nss_dns/dns-canon.c
+++ b/resolv/nss_dns/dns-canon.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2004, 2006 Free Software Foundation, Inc.
+/* Copyright (C) 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
@@ -40,10 +40,6 @@ typedef union querybuf
} querybuf;
-static const short int qtypes[] = { ns_t_a, ns_t_aaaa };
-#define nqtypes (sizeof (qtypes) / sizeof (qtypes[0]))
-
-
enum nss_status
_nss_dns_getcanonname_r (const char *name, char *buffer, size_t buflen,
char **result,int *errnop, int *h_errnop)
@@ -57,6 +53,8 @@ _nss_dns_getcanonname_r (const char *name, char *buffer, size_t buflen,
unsigned char *ptr;
} ansp = { .ptr = buf };
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)
{
@@ -103,8 +101,7 @@ _nss_dns_getcanonname_r (const char *name, char *buffer, size_t buflen,
ptr += s;
/* Check whether type and class match. */
- uint_fast16_t type;
- NS_GET16 (type, ptr);
+ unsigned int type = ntohs (*(uint16_t *) ptr);
if (type == qtypes[i])
{
/* We found the record. */
@@ -133,14 +130,15 @@ _nss_dns_getcanonname_r (const char *name, char *buffer, size_t buflen,
if (type != ns_t_cname)
goto unavail;
- if (ns_get16 (ptr) != ns_c_in)
+ ptr += sizeof (uint16_t);
+ if (*(uint16_t *) ptr != htons (ns_c_in))
goto unavail;
/* Also skip over the TTL. */
ptr += sizeof (uint16_t) + sizeof (uint32_t);
/* Skip over the data length and data. */
- ptr += sizeof (uint16_t) + ns_get16 (ptr);
+ ptr += sizeof (uint16_t) + ntohs (*(uint16_t *) ptr);
}
}
}
diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c
index cf060be8ef..7045c5915b 100644
--- a/resolv/nss_dns/dns-host.c
+++ b/resolv/nss_dns/dns-host.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996-2003, 2004, 2007 Free Software Foundation, Inc.
+/* Copyright (C) 1996-2003, 2004 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Extended from original form by Ulrich Drepper <drepper@cygnus.com>, 1996.
@@ -465,8 +465,8 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
char *aliases[MAX_NR_ALIASES];
unsigned char host_addr[16]; /* IPv4 or IPv6 */
char *h_addr_ptrs[0];
- } *host_data;
- int linebuflen;
+ } *host_data = (struct host_data *) buffer;
+ int linebuflen = buflen - sizeof (struct host_data);
register const HEADER *hp;
const u_char *end_of_message, *cp;
int n, ancount, qdcount;
@@ -478,9 +478,8 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
u_char packtmp[NS_MAXCDNAME];
int have_to_map = 0;
int32_t ttl = 0;
- uintptr_t pad = -(uintptr_t) buffer % __alignof__ (struct host_data);
- buffer += pad;
- if (__builtin_expect (buflen < sizeof (struct host_data) + pad, 0))
+
+ if (__builtin_expect (linebuflen, 0) < 0)
{
/* The buffer is too small. */
too_small:
@@ -488,10 +487,6 @@ getanswer_r (const querybuf *answer, int anslen, const char *qname, int qtype,
*h_errnop = NETDB_INTERNAL;
return NSS_STATUS_TRYAGAIN;
}
- host_data = (struct host_data *) buffer;
- linebuflen = buflen - sizeof (struct host_data);
- if (buflen - sizeof (struct host_data) != linebuflen)
- linebuflen = INT_MAX;
tname = qname;
result->h_name = NULL;
diff --git a/resolv/nss_dns/dns-network.c b/resolv/nss_dns/dns-network.c
index 4552b5b678..6ff60f3119 100644
--- a/resolv/nss_dns/dns-network.c
+++ b/resolv/nss_dns/dns-network.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1996, 1997, 1998, 1999, 2002, 2004, 2007
+/* Copyright (C) 1996, 1997, 1998, 1999, 2002, 2004
Free Software Foundation, Inc.
This file is part of the GNU C Library.
Extended from original form by Ulrich Drepper <drepper@cygnus.com>, 1996.
@@ -102,8 +102,7 @@ extern int __ns_name_unpack (const u_char *, const u_char *,
/* Prototypes for local functions. */
static enum nss_status getanswer_r (const querybuf *answer, int anslen,
struct netent *result, char *buffer,
- size_t buflen, int *errnop, int *h_errnop,
- lookup_method net_i);
+ size_t buflen, lookup_method net_i);
enum nss_status
@@ -143,8 +142,7 @@ _nss_dns_getnetbyname_r (const char *name, struct netent *result,
? NSS_STATUS_UNAVAIL : NSS_STATUS_NOTFOUND;
}
- status = getanswer_r (net_buffer.buf, anslen, result, buffer, buflen,
- errnop, herrnop, BYNAME);
+ status = getanswer_r (net_buffer.buf, anslen, result, buffer, buflen, BYNAME);
if (net_buffer.buf != orig_net_buffer)
free (net_buffer.buf);
return status;
@@ -220,8 +218,7 @@ _nss_dns_getnetbyaddr_r (uint32_t net, int type, struct netent *result,
? NSS_STATUS_UNAVAIL : NSS_STATUS_NOTFOUND;
}
- status = getanswer_r (net_buffer.buf, anslen, result, buffer, buflen,
- errnop, herrnop, BYADDR);
+ status = getanswer_r (net_buffer.buf, anslen, result, buffer, buflen, BYADDR);
if (net_buffer.buf != orig_net_buffer)
free (net_buffer.buf);
if (status == NSS_STATUS_SUCCESS)
@@ -243,8 +240,7 @@ _nss_dns_getnetbyaddr_r (uint32_t net, int type, struct netent *result,
static enum nss_status
getanswer_r (const querybuf *answer, int anslen, struct netent *result,
- char *buffer, size_t buflen, int *errnop, int *h_errnop,
- lookup_method net_i)
+ char *buffer, size_t buflen, lookup_method net_i)
{
/*
* Find first satisfactory answer
@@ -264,33 +260,16 @@ getanswer_r (const querybuf *answer, int anslen, struct netent *result,
{
char *aliases[MAX_NR_ALIASES];
char linebuffer[0];
- } *net_data;
-
- uintptr_t pad = -(uintptr_t) buffer % __alignof__ (struct net_data);
- buffer += pad;
-
- if (__builtin_expect (buflen < sizeof (*net_data) + pad, 0))
- {
- /* The buffer is too small. */
- too_small:
- *errnop = ERANGE;
- *h_errnop = NETDB_INTERNAL;
- return NSS_STATUS_TRYAGAIN;
- }
- buflen -= pad;
-
- net_data = (struct net_data *) buffer;
+ } *net_data = (struct net_data *) buffer;
int linebuflen = buflen - offsetof (struct net_data, linebuffer);
- if (buflen - offsetof (struct net_data, linebuffer) != linebuflen)
- linebuflen = INT_MAX;
- const unsigned char *end_of_message = &answer->buf[anslen];
+ const char *end_of_message = &answer->buf[anslen];
const HEADER *header_pointer = &answer->hdr;
/* #/records in the answer section. */
int answer_count = ntohs (header_pointer->ancount);
/* #/entries in the question section. */
int question_count = ntohs (header_pointer->qdcount);
char *bp = net_data->linebuffer;
- const unsigned char *cp = &answer->buf[HFIXEDSZ];
+ const char *cp = &answer->buf[HFIXEDSZ];
char **alias_pointer;
int have_answer;
char *ans;
@@ -340,7 +319,10 @@ getanswer_r (const querybuf *answer, int anslen, struct netent *result,
if (n != -1 && __ns_name_ntop (packtmp, bp, linebuflen) == -1)
{
if (errno == EMSGSIZE)
- goto too_small;
+ {
+ errno = ERANGE;
+ return NSS_STATUS_TRYAGAIN;
+ }
n = -1;
}
@@ -364,7 +346,10 @@ getanswer_r (const querybuf *answer, int anslen, struct netent *result,
if (n != -1 && __ns_name_ntop (packtmp, bp, linebuflen) == -1)
{
if (errno == EMSGSIZE)
- goto too_small;
+ {
+ errno = ERANGE;
+ return NSS_STATUS_TRYAGAIN;
+ }
n = -1;
}