mirror of
https://sourceware.org/git/glibc.git
synced 2024-12-22 10:50:07 +00:00
* resolv/nss_dns/dns-host.c (_nss_dns_gethostbyaddr_r): Use union type to avoid strict aliasing problem. (_nss_dns_gethostbyname2_r): Likewise. * resolv/nss_dns/dns-network.c (_nss_dns_getnetbyaddr_r): Likewise. (_nss_dns_getnetbyname_r): Likewise.
* resolv/gethnamaddr.c (_gethtent): Likewise. (gethostbyname2): Likewise.
This commit is contained in:
parent
ee2a5ae875
commit
16b6606283
@ -262,9 +262,9 @@ getanswer(answer, anslen, qname, qtype)
|
|||||||
cp += n; /* name */
|
cp += n; /* name */
|
||||||
BOUNDS_CHECK(cp, 3 * INT16SZ + INT32SZ);
|
BOUNDS_CHECK(cp, 3 * INT16SZ + INT32SZ);
|
||||||
type = ns_get16(cp);
|
type = ns_get16(cp);
|
||||||
cp += INT16SZ; /* type */
|
cp += INT16SZ; /* type */
|
||||||
class = ns_get16(cp);
|
class = ns_get16(cp);
|
||||||
cp += INT16SZ + INT32SZ; /* class, TTL */
|
cp += INT16SZ + INT32SZ; /* class, TTL */
|
||||||
n = ns_get16(cp);
|
n = ns_get16(cp);
|
||||||
cp += INT16SZ; /* len */
|
cp += INT16SZ; /* len */
|
||||||
BOUNDS_CHECK(cp, n);
|
BOUNDS_CHECK(cp, n);
|
||||||
@ -510,7 +510,12 @@ gethostbyname2(name, af)
|
|||||||
const char *name;
|
const char *name;
|
||||||
int af;
|
int af;
|
||||||
{
|
{
|
||||||
querybuf *buf, *origbuf;
|
union
|
||||||
|
{
|
||||||
|
querybuf *buf;
|
||||||
|
u_char *ptr;
|
||||||
|
} buf;
|
||||||
|
querybuf *origbuf;
|
||||||
register const char *cp;
|
register const char *cp;
|
||||||
char *bp;
|
char *bp;
|
||||||
int n, size, type, len;
|
int n, size, type, len;
|
||||||
@ -616,20 +621,20 @@ gethostbyname2(name, af)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = origbuf = (querybuf *) alloca (1024);
|
buf.buf = origbuf = (querybuf *) alloca (1024);
|
||||||
|
|
||||||
if ((n = __libc_res_nsearch(&_res, name, C_IN, type, buf->buf, 1024,
|
if ((n = __libc_res_nsearch(&_res, name, C_IN, type, buf.buf->buf, 1024,
|
||||||
(u_char **) &buf)) < 0) {
|
&buf.ptr)) < 0) {
|
||||||
if (buf != origbuf)
|
if (buf.buf != origbuf)
|
||||||
free (buf);
|
free (buf.buf);
|
||||||
dprintf("res_nsearch failed (%d)\n", n);
|
dprintf("res_nsearch failed (%d)\n", n);
|
||||||
if (errno == ECONNREFUSED)
|
if (errno == ECONNREFUSED)
|
||||||
return (_gethtbyname2(name, af));
|
return (_gethtbyname2(name, af));
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
ret = getanswer(buf, n, name, type);
|
ret = getanswer(buf.buf, n, name, type);
|
||||||
if (buf != origbuf)
|
if (buf.buf != origbuf)
|
||||||
free (buf);
|
free (buf.buf);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -644,7 +649,12 @@ gethostbyaddr(addr, len, af)
|
|||||||
static const u_char tunnelled[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 };
|
static const u_char tunnelled[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 };
|
||||||
int n;
|
int n;
|
||||||
socklen_t size;
|
socklen_t size;
|
||||||
querybuf *buf, *orig_buf;
|
union
|
||||||
|
{
|
||||||
|
querybuf *buf;
|
||||||
|
u_char *ptr;
|
||||||
|
} buf;
|
||||||
|
querybuf *orig_buf;
|
||||||
register struct hostent *hp;
|
register struct hostent *hp;
|
||||||
char qbuf[MAXDNAME+1], *qp = NULL;
|
char qbuf[MAXDNAME+1], *qp = NULL;
|
||||||
#ifdef SUNSECURITY
|
#ifdef SUNSECURITY
|
||||||
@ -706,27 +716,27 @@ gethostbyaddr(addr, len, af)
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = orig_buf = (querybuf *) alloca (1024);
|
buf.buf = orig_buf = (querybuf *) alloca (1024);
|
||||||
|
|
||||||
n = __libc_res_nquery(&_res, qbuf, C_IN, T_PTR, buf->buf, 1024,
|
n = __libc_res_nquery(&_res, qbuf, C_IN, T_PTR, buf.buf->buf, 1024,
|
||||||
(u_char **) &buf);
|
&buf.ptr);
|
||||||
if (n < 0 && af == AF_INET6) {
|
if (n < 0 && af == AF_INET6) {
|
||||||
strcpy(qp, "ip6.int");
|
strcpy(qp, "ip6.int");
|
||||||
n = __libc_res_nquery(&_res, qbuf, C_IN, T_PTR, buf->buf,
|
n = __libc_res_nquery(&_res, qbuf, C_IN, T_PTR, buf.buf->buf,
|
||||||
buf != orig_buf ? MAXPACKET : 1024,
|
buf.buf != orig_buf ? MAXPACKET : 1024,
|
||||||
(u_char **) &buf);
|
&buf.ptr);
|
||||||
}
|
}
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
if (buf != orig_buf)
|
if (buf.buf != orig_buf)
|
||||||
free (buf);
|
free (buf.buf);
|
||||||
dprintf("res_nquery failed (%d)\n", n);
|
dprintf("res_nquery failed (%d)\n", n);
|
||||||
if (errno == ECONNREFUSED)
|
if (errno == ECONNREFUSED)
|
||||||
return (_gethtbyaddr(addr, len, af));
|
return (_gethtbyaddr(addr, len, af));
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
hp = getanswer(buf, n, qbuf, T_PTR);
|
hp = getanswer(buf.buf, n, qbuf, T_PTR);
|
||||||
if (buf != orig_buf)
|
if (buf.buf != orig_buf)
|
||||||
free (buf);
|
free (buf.buf);
|
||||||
if (!hp)
|
if (!hp)
|
||||||
return (NULL); /* h_errno was set by getanswer() */
|
return (NULL); /* h_errno was set by getanswer() */
|
||||||
#ifdef SUNSECURITY
|
#ifdef SUNSECURITY
|
||||||
|
@ -132,7 +132,12 @@ _nss_dns_gethostbyname2_r (const char *name, int af, struct hostent *result,
|
|||||||
char *buffer, size_t buflen, int *errnop,
|
char *buffer, size_t buflen, int *errnop,
|
||||||
int *h_errnop)
|
int *h_errnop)
|
||||||
{
|
{
|
||||||
querybuf *host_buffer, *orig_host_buffer;
|
union
|
||||||
|
{
|
||||||
|
querybuf *buf;
|
||||||
|
u_char *ptr;
|
||||||
|
} host_buffer;
|
||||||
|
querybuf *orig_host_buffer;
|
||||||
char tmp[NS_MAXDNAME];
|
char tmp[NS_MAXDNAME];
|
||||||
int size, type, n;
|
int size, type, n;
|
||||||
const char *cp;
|
const char *cp;
|
||||||
@ -170,10 +175,10 @@ _nss_dns_gethostbyname2_r (const char *name, int af, struct hostent *result,
|
|||||||
&& (cp = res_hostalias (&_res, name, tmp, sizeof (tmp))) != NULL)
|
&& (cp = res_hostalias (&_res, name, tmp, sizeof (tmp))) != NULL)
|
||||||
name = cp;
|
name = cp;
|
||||||
|
|
||||||
host_buffer = orig_host_buffer = (querybuf *) alloca (1024);
|
host_buffer.buf = orig_host_buffer = (querybuf *) alloca (1024);
|
||||||
|
|
||||||
n = __libc_res_nsearch (&_res, name, C_IN, type, host_buffer->buf,
|
n = __libc_res_nsearch (&_res, name, C_IN, type, host_buffer.buf->buf,
|
||||||
1024, (u_char **) &host_buffer);
|
1024, &host_buffer.ptr);
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
enum nss_status status = (errno == ECONNREFUSED
|
enum nss_status status = (errno == ECONNREFUSED
|
||||||
@ -188,14 +193,14 @@ _nss_dns_gethostbyname2_r (const char *name, int af, struct hostent *result,
|
|||||||
by having the RES_USE_INET6 bit in _res.options set, we try
|
by having the RES_USE_INET6 bit in _res.options set, we try
|
||||||
another lookup. */
|
another lookup. */
|
||||||
if (af == AF_INET6 && (_res.options & RES_USE_INET6))
|
if (af == AF_INET6 && (_res.options & RES_USE_INET6))
|
||||||
n = __libc_res_nsearch (&_res, name, C_IN, T_A, host_buffer->buf,
|
n = __libc_res_nsearch (&_res, name, C_IN, T_A, host_buffer.buf->buf,
|
||||||
host_buffer != orig_host_buffer
|
host_buffer.buf != orig_host_buffer
|
||||||
? MAXPACKET : 1024, (u_char **) &host_buffer);
|
? MAXPACKET : 1024, &host_buffer.ptr);
|
||||||
|
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
if (host_buffer != orig_host_buffer)
|
if (host_buffer.buf != orig_host_buffer)
|
||||||
free (host_buffer);
|
free (host_buffer.buf);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,10 +210,10 @@ _nss_dns_gethostbyname2_r (const char *name, int af, struct hostent *result,
|
|||||||
result->h_length = INADDRSZ;;
|
result->h_length = INADDRSZ;;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = getanswer_r (host_buffer, n, name, type, result, buffer, buflen,
|
status = getanswer_r (host_buffer.buf, n, name, type, result, buffer, buflen,
|
||||||
errnop, h_errnop, map);
|
errnop, h_errnop, map);
|
||||||
if (host_buffer != orig_host_buffer)
|
if (host_buffer.buf != orig_host_buffer)
|
||||||
free (host_buffer);
|
free (host_buffer.buf);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,7 +252,12 @@ _nss_dns_gethostbyaddr_r (const void *addr, socklen_t len, int af,
|
|||||||
char *h_addr_ptrs[MAX_NR_ADDRS + 1];
|
char *h_addr_ptrs[MAX_NR_ADDRS + 1];
|
||||||
char linebuffer[0];
|
char linebuffer[0];
|
||||||
} *host_data = (struct host_data *) buffer;
|
} *host_data = (struct host_data *) buffer;
|
||||||
querybuf *host_buffer, *orig_host_buffer;
|
union
|
||||||
|
{
|
||||||
|
querybuf *buf;
|
||||||
|
u_char *ptr;
|
||||||
|
} host_buffer;
|
||||||
|
querybuf *orig_host_buffer;
|
||||||
char qbuf[MAXDNAME+1], *qp = NULL;
|
char qbuf[MAXDNAME+1], *qp = NULL;
|
||||||
size_t size;
|
size_t size;
|
||||||
int n, status;
|
int n, status;
|
||||||
@ -305,30 +315,30 @@ _nss_dns_gethostbyaddr_r (const void *addr, socklen_t len, int af,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
host_buffer = orig_host_buffer = (querybuf *) alloca (1024);
|
host_buffer.buf = orig_host_buffer = (querybuf *) alloca (1024);
|
||||||
|
|
||||||
n = __libc_res_nquery (&_res, qbuf, C_IN, T_PTR, host_buffer->buf,
|
n = __libc_res_nquery (&_res, qbuf, C_IN, T_PTR, host_buffer.buf->buf,
|
||||||
1024, (u_char **) &host_buffer);
|
1024, &host_buffer.ptr);
|
||||||
if (n < 0 && af == AF_INET6)
|
if (n < 0 && af == AF_INET6)
|
||||||
{
|
{
|
||||||
strcpy (qp, "ip6.int");
|
strcpy (qp, "ip6.int");
|
||||||
n = __libc_res_nquery (&_res, qbuf, C_IN, T_PTR, host_buffer->buf,
|
n = __libc_res_nquery (&_res, qbuf, C_IN, T_PTR, host_buffer.buf->buf,
|
||||||
host_buffer != orig_host_buffer
|
host_buffer.buf != orig_host_buffer
|
||||||
? MAXPACKET : 1024, (u_char **) &host_buffer);
|
? MAXPACKET : 1024, &host_buffer.ptr);
|
||||||
}
|
}
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
{
|
{
|
||||||
*h_errnop = h_errno;
|
*h_errnop = h_errno;
|
||||||
__set_errno (olderr);
|
__set_errno (olderr);
|
||||||
if (host_buffer != orig_host_buffer)
|
if (host_buffer.buf != orig_host_buffer)
|
||||||
free (host_buffer);
|
free (host_buffer.buf);
|
||||||
return errno == ECONNREFUSED ? NSS_STATUS_UNAVAIL : NSS_STATUS_NOTFOUND;
|
return errno == ECONNREFUSED ? NSS_STATUS_UNAVAIL : NSS_STATUS_NOTFOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = getanswer_r (host_buffer, n, qbuf, T_PTR, result, buffer, buflen,
|
status = getanswer_r (host_buffer.buf, n, qbuf, T_PTR, result, buffer, buflen,
|
||||||
errnop, h_errnop, 0 /* XXX */);
|
errnop, h_errnop, 0 /* XXX */);
|
||||||
if (host_buffer != orig_host_buffer)
|
if (host_buffer.buf != orig_host_buffer)
|
||||||
free (host_buffer);
|
free (host_buffer.buf);
|
||||||
if (status != NSS_STATUS_SUCCESS)
|
if (status != NSS_STATUS_SUCCESS)
|
||||||
{
|
{
|
||||||
*h_errnop = h_errno;
|
*h_errnop = h_errno;
|
||||||
|
@ -110,7 +110,12 @@ _nss_dns_getnetbyname_r (const char *name, struct netent *result,
|
|||||||
int *herrnop)
|
int *herrnop)
|
||||||
{
|
{
|
||||||
/* Return entry for network with NAME. */
|
/* Return entry for network with NAME. */
|
||||||
querybuf *net_buffer, *orig_net_buffer;
|
union
|
||||||
|
{
|
||||||
|
querybuf *buf;
|
||||||
|
u_char *ptr;
|
||||||
|
} net_buffer;
|
||||||
|
querybuf *orig_net_buffer;
|
||||||
int anslen;
|
int anslen;
|
||||||
char *qbuf;
|
char *qbuf;
|
||||||
enum nss_status status;
|
enum nss_status status;
|
||||||
@ -120,25 +125,25 @@ _nss_dns_getnetbyname_r (const char *name, struct netent *result,
|
|||||||
|
|
||||||
qbuf = strdupa (name);
|
qbuf = strdupa (name);
|
||||||
|
|
||||||
net_buffer = orig_net_buffer = (querybuf *) alloca (1024);
|
net_buffer.buf = orig_net_buffer = (querybuf *) alloca (1024);
|
||||||
|
|
||||||
anslen = __libc_res_nsearch (&_res, qbuf, C_IN, T_PTR, net_buffer->buf,
|
anslen = __libc_res_nsearch (&_res, qbuf, C_IN, T_PTR, net_buffer.buf->buf,
|
||||||
1024, (u_char **) &net_buffer);
|
1024, &net_buffer.ptr);
|
||||||
if (anslen < 0)
|
if (anslen < 0)
|
||||||
{
|
{
|
||||||
/* Nothing found. */
|
/* Nothing found. */
|
||||||
*errnop = errno;
|
*errnop = errno;
|
||||||
if (net_buffer != orig_net_buffer)
|
if (net_buffer.buf != orig_net_buffer)
|
||||||
free (net_buffer);
|
free (net_buffer.buf);
|
||||||
return (errno == ECONNREFUSED
|
return (errno == ECONNREFUSED
|
||||||
|| errno == EPFNOSUPPORT
|
|| errno == EPFNOSUPPORT
|
||||||
|| errno == EAFNOSUPPORT)
|
|| errno == EAFNOSUPPORT)
|
||||||
? NSS_STATUS_UNAVAIL : NSS_STATUS_NOTFOUND;
|
? NSS_STATUS_UNAVAIL : NSS_STATUS_NOTFOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = getanswer_r (net_buffer, anslen, result, buffer, buflen, BYNAME);
|
status = getanswer_r (net_buffer.buf, anslen, result, buffer, buflen, BYNAME);
|
||||||
if (net_buffer != orig_net_buffer)
|
if (net_buffer.buf != orig_net_buffer)
|
||||||
free (net_buffer);
|
free (net_buffer.buf);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,7 +155,12 @@ _nss_dns_getnetbyaddr_r (uint32_t net, int type, struct netent *result,
|
|||||||
{
|
{
|
||||||
/* Return entry for network with NAME. */
|
/* Return entry for network with NAME. */
|
||||||
enum nss_status status;
|
enum nss_status status;
|
||||||
querybuf *net_buffer, *orig_net_buffer;
|
union
|
||||||
|
{
|
||||||
|
querybuf *buf;
|
||||||
|
u_char *ptr;
|
||||||
|
} net_buffer;
|
||||||
|
querybuf *orig_net_buffer;
|
||||||
unsigned int net_bytes[4];
|
unsigned int net_bytes[4];
|
||||||
char qbuf[MAXDNAME];
|
char qbuf[MAXDNAME];
|
||||||
int cnt, anslen;
|
int cnt, anslen;
|
||||||
@ -190,26 +200,26 @@ _nss_dns_getnetbyaddr_r (uint32_t net, int type, struct netent *result,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
net_buffer = orig_net_buffer = (querybuf *) alloca (1024);
|
net_buffer.buf = orig_net_buffer = (querybuf *) alloca (1024);
|
||||||
|
|
||||||
anslen = __libc_res_nquery (&_res, qbuf, C_IN, T_PTR, net_buffer->buf,
|
anslen = __libc_res_nquery (&_res, qbuf, C_IN, T_PTR, net_buffer.buf->buf,
|
||||||
1024, (u_char **) &net_buffer);
|
1024, &net_buffer.ptr);
|
||||||
if (anslen < 0)
|
if (anslen < 0)
|
||||||
{
|
{
|
||||||
/* Nothing found. */
|
/* Nothing found. */
|
||||||
int err = errno;
|
int err = errno;
|
||||||
__set_errno (olderr);
|
__set_errno (olderr);
|
||||||
if (net_buffer != orig_net_buffer)
|
if (net_buffer.buf != orig_net_buffer)
|
||||||
free (net_buffer);
|
free (net_buffer.buf);
|
||||||
return (err == ECONNREFUSED
|
return (err == ECONNREFUSED
|
||||||
|| err == EPFNOSUPPORT
|
|| err == EPFNOSUPPORT
|
||||||
|| err == EAFNOSUPPORT)
|
|| err == EAFNOSUPPORT)
|
||||||
? NSS_STATUS_UNAVAIL : NSS_STATUS_NOTFOUND;
|
? NSS_STATUS_UNAVAIL : NSS_STATUS_NOTFOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = getanswer_r (net_buffer, anslen, result, buffer, buflen, BYADDR);
|
status = getanswer_r (net_buffer.buf, anslen, result, buffer, buflen, BYADDR);
|
||||||
if (net_buffer != orig_net_buffer)
|
if (net_buffer.buf != orig_net_buffer)
|
||||||
free (net_buffer);
|
free (net_buffer.buf);
|
||||||
if (status == NSS_STATUS_SUCCESS)
|
if (status == NSS_STATUS_SUCCESS)
|
||||||
{
|
{
|
||||||
/* Strip trailing zeros. */
|
/* Strip trailing zeros. */
|
||||||
|
Loading…
Reference in New Issue
Block a user