mirror of
https://sourceware.org/git/glibc.git
synced 2025-07-30 22:43:12 +03:00
resolv: Report allocation errors in __res_vinit
This commit is contained in:
12
ChangeLog
12
ChangeLog
@ -1,3 +1,15 @@
|
|||||||
|
2017-06-19 Florian Weimer <fweimer@redhat.com>
|
||||||
|
|
||||||
|
* resolv/res_init.c (res_vinit_1): New function.
|
||||||
|
(__res_vinit): Call it. Handle file open and memory allocation
|
||||||
|
failures.
|
||||||
|
* resolv/nss_dns/dns-host.c (_nss_dns_gethostbyname3_r): Propagate
|
||||||
|
erno from __res_maybe_init failure.
|
||||||
|
(_nss_dns_gethostbyname4_r): Likewise.
|
||||||
|
(_nss_dns_gethostbyaddr2_r): Likewise.
|
||||||
|
* resolv/nss_dns/dns-network.c (_nss_dns_getnetbyname_r): Likewise.
|
||||||
|
(_nss_dns_getnetbyaddr_r): Likewise.
|
||||||
|
|
||||||
2017-06-19 Florian Weimer <fweimer@redhat.com>
|
2017-06-19 Florian Weimer <fweimer@redhat.com>
|
||||||
|
|
||||||
* resolv/res_init.c: Reformat to GNU style.
|
* resolv/res_init.c: Reformat to GNU style.
|
||||||
|
@ -164,7 +164,11 @@ _nss_dns_gethostbyname3_r (const char *name, int af, struct hostent *result,
|
|||||||
enum nss_status status;
|
enum nss_status status;
|
||||||
|
|
||||||
if (__res_maybe_init (&_res, 0) == -1)
|
if (__res_maybe_init (&_res, 0) == -1)
|
||||||
return NSS_STATUS_UNAVAIL;
|
{
|
||||||
|
*errnop = errno;
|
||||||
|
*h_errnop = NETDB_INTERNAL;
|
||||||
|
return NSS_STATUS_UNAVAIL;
|
||||||
|
}
|
||||||
|
|
||||||
switch (af) {
|
switch (af) {
|
||||||
case AF_INET:
|
case AF_INET:
|
||||||
@ -289,7 +293,11 @@ _nss_dns_gethostbyname4_r (const char *name, struct gaih_addrtuple **pat,
|
|||||||
int *herrnop, int32_t *ttlp)
|
int *herrnop, int32_t *ttlp)
|
||||||
{
|
{
|
||||||
if (__res_maybe_init (&_res, 0) == -1)
|
if (__res_maybe_init (&_res, 0) == -1)
|
||||||
return NSS_STATUS_UNAVAIL;
|
{
|
||||||
|
*errnop = errno;
|
||||||
|
*herrnop = NETDB_INTERNAL;
|
||||||
|
return NSS_STATUS_UNAVAIL;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* if there aren't any dots, it could be a user-level alias.
|
* if there aren't any dots, it could be a user-level alias.
|
||||||
@ -416,7 +424,11 @@ _nss_dns_gethostbyaddr2_r (const void *addr, socklen_t len, int af,
|
|||||||
host_data = (struct host_data *) buffer;
|
host_data = (struct host_data *) buffer;
|
||||||
|
|
||||||
if (__res_maybe_init (&_res, 0) == -1)
|
if (__res_maybe_init (&_res, 0) == -1)
|
||||||
return NSS_STATUS_UNAVAIL;
|
{
|
||||||
|
*errnop = errno;
|
||||||
|
*h_errnop = NETDB_INTERNAL;
|
||||||
|
return NSS_STATUS_UNAVAIL;
|
||||||
|
}
|
||||||
|
|
||||||
if (af == AF_INET6 && len == IN6ADDRSZ
|
if (af == AF_INET6 && len == IN6ADDRSZ
|
||||||
&& (memcmp (uaddr, mapped, sizeof mapped) == 0
|
&& (memcmp (uaddr, mapped, sizeof mapped) == 0
|
||||||
|
@ -116,7 +116,11 @@ _nss_dns_getnetbyname_r (const char *name, struct netent *result,
|
|||||||
enum nss_status status;
|
enum nss_status status;
|
||||||
|
|
||||||
if (__res_maybe_init (&_res, 0) == -1)
|
if (__res_maybe_init (&_res, 0) == -1)
|
||||||
return NSS_STATUS_UNAVAIL;
|
{
|
||||||
|
*errnop = errno;
|
||||||
|
*herrnop = NETDB_INTERNAL;
|
||||||
|
return NSS_STATUS_UNAVAIL;
|
||||||
|
}
|
||||||
|
|
||||||
net_buffer.buf = orig_net_buffer = (querybuf *) alloca (1024);
|
net_buffer.buf = orig_net_buffer = (querybuf *) alloca (1024);
|
||||||
|
|
||||||
@ -166,7 +170,11 @@ _nss_dns_getnetbyaddr_r (uint32_t net, int type, struct netent *result,
|
|||||||
return NSS_STATUS_UNAVAIL;
|
return NSS_STATUS_UNAVAIL;
|
||||||
|
|
||||||
if (__res_maybe_init (&_res, 0) == -1)
|
if (__res_maybe_init (&_res, 0) == -1)
|
||||||
return NSS_STATUS_UNAVAIL;
|
{
|
||||||
|
*errnop = errno;
|
||||||
|
*herrnop = NETDB_INTERNAL;
|
||||||
|
return NSS_STATUS_UNAVAIL;
|
||||||
|
}
|
||||||
|
|
||||||
net2 = (u_int32_t) net;
|
net2 = (u_int32_t) net;
|
||||||
for (cnt = 4; net2 != 0; net2 >>= 8)
|
for (cnt = 4; net2 != 0; net2 >>= 8)
|
||||||
|
@ -100,6 +100,7 @@
|
|||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <inet/net-internal.h>
|
#include <inet/net-internal.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
static void res_setoptions (res_state, const char *, const char *);
|
static void res_setoptions (res_state, const char *, const char *);
|
||||||
static uint32_t net_mask (struct in_addr);
|
static uint32_t net_mask (struct in_addr);
|
||||||
@ -121,14 +122,11 @@ is_sort_mask (char ch)
|
|||||||
return ch == '/' || ch == '&';
|
return ch == '/' || ch == '&';
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set up default settings. If the /etc/resolv.conf configuration
|
/* Internal helper function for __res_vinit, to aid with resource
|
||||||
file exist, the values there will have precedence. Otherwise, the
|
deallocation and error handling. Return true on success, false on
|
||||||
server address is set to INADDR_LOOPBACK and the default domain
|
failure. */
|
||||||
name comes from gethostname. The RES_OPTIONS and LOCALDOMAIN
|
static bool
|
||||||
environment variables can be used to override some settings.
|
res_vinit_1 (res_state statp, bool preinit, FILE *fp)
|
||||||
Return 0 if completes successfully, -1 on error. */
|
|
||||||
int
|
|
||||||
__res_vinit (res_state statp, int preinit)
|
|
||||||
{
|
{
|
||||||
char *cp, **pp;
|
char *cp, **pp;
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
@ -203,7 +201,6 @@ __res_vinit (res_state statp, int preinit)
|
|||||||
&& (line[sizeof (name) - 1] == ' ' \
|
&& (line[sizeof (name) - 1] == ' ' \
|
||||||
|| line[sizeof (name) - 1] == '\t'))
|
|| line[sizeof (name) - 1] == '\t'))
|
||||||
|
|
||||||
FILE *fp = fopen (_PATH_RESCONF, "rce");
|
|
||||||
if (fp != NULL)
|
if (fp != NULL)
|
||||||
{
|
{
|
||||||
/* No threads use this stream. */
|
/* No threads use this stream. */
|
||||||
@ -302,26 +299,26 @@ __res_vinit (res_state statp, int preinit)
|
|||||||
struct sockaddr_in6 *sa6;
|
struct sockaddr_in6 *sa6;
|
||||||
|
|
||||||
sa6 = malloc (sizeof (*sa6));
|
sa6 = malloc (sizeof (*sa6));
|
||||||
if (sa6 != NULL)
|
if (sa6 == NULL)
|
||||||
{
|
return -1;
|
||||||
sa6->sin6_family = AF_INET6;
|
|
||||||
sa6->sin6_port = htons (NAMESERVER_PORT);
|
|
||||||
sa6->sin6_flowinfo = 0;
|
|
||||||
sa6->sin6_addr = a6;
|
|
||||||
|
|
||||||
sa6->sin6_scope_id = 0;
|
sa6->sin6_family = AF_INET6;
|
||||||
if (__glibc_likely (el != NULL))
|
sa6->sin6_port = htons (NAMESERVER_PORT);
|
||||||
/* Ignore errors, for backwards
|
sa6->sin6_flowinfo = 0;
|
||||||
compatibility. */
|
sa6->sin6_addr = a6;
|
||||||
__inet6_scopeid_pton
|
|
||||||
(&a6, el + 1, &sa6->sin6_scope_id);
|
|
||||||
|
|
||||||
statp->nsaddr_list[nserv].sin_family = 0;
|
sa6->sin6_scope_id = 0;
|
||||||
statp->_u._ext.nsaddrs[nserv] = sa6;
|
if (__glibc_likely (el != NULL))
|
||||||
statp->_u._ext.nssocks[nserv] = -1;
|
/* Ignore errors, for backwards
|
||||||
have_serv6 = true;
|
compatibility. */
|
||||||
nserv++;
|
__inet6_scopeid_pton
|
||||||
}
|
(&a6, el + 1, &sa6->sin6_scope_id);
|
||||||
|
|
||||||
|
statp->nsaddr_list[nserv].sin_family = 0;
|
||||||
|
statp->_u._ext.nsaddrs[nserv] = sa6;
|
||||||
|
statp->_u._ext.nssocks[nserv] = -1;
|
||||||
|
have_serv6 = true;
|
||||||
|
nserv++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
@ -410,6 +407,44 @@ __res_vinit (res_state statp, int preinit)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Set up default settings. If the /etc/resolv.conf configuration
|
||||||
|
file exist, the values there will have precedence. Otherwise, the
|
||||||
|
server address is set to INADDR_LOOPBACK and the default domain
|
||||||
|
name comes from gethostname. The RES_OPTIONS and LOCALDOMAIN
|
||||||
|
environment variables can be used to override some settings.
|
||||||
|
Return 0 if completes successfully, -1 on error. */
|
||||||
|
int
|
||||||
|
__res_vinit (res_state statp, int preinit)
|
||||||
|
{
|
||||||
|
FILE *fp = fopen (_PATH_RESCONF, "rce");
|
||||||
|
if (fp == NULL)
|
||||||
|
switch (errno)
|
||||||
|
{
|
||||||
|
case EACCES:
|
||||||
|
case EISDIR:
|
||||||
|
case ELOOP:
|
||||||
|
case ENOENT:
|
||||||
|
case ENOTDIR:
|
||||||
|
case EPERM:
|
||||||
|
/* Ignore these errors. They are persistent errors caused
|
||||||
|
by file system contents. */
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
/* Other errors refer to resource allocation problems and
|
||||||
|
need to be handled by the application. */
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (!res_vinit_1 (statp, preinit, fp))
|
||||||
|
{
|
||||||
|
/* Deallocate the name server addresses which have been
|
||||||
|
allocated. */
|
||||||
|
for (int n = 0; n < MAXNS; n++)
|
||||||
|
free (statp->_u._ext.nsaddrs[n]);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
res_setoptions (res_state statp, const char *options, const char *source)
|
res_setoptions (res_state statp, const char *options, const char *source)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user