hostalias() is not thread-safe. So, introduce _res_hostalias()

and use it.

Obtained from:	BIND9
This commit is contained in:
ume 2005-04-15 14:42:29 +00:00
parent 53377abba9
commit b8a79c699c
3 changed files with 29 additions and 14 deletions

View File

@ -2283,7 +2283,7 @@ _yp_getaddrinfo(rv, cb_data, ap)
/* resolver logic */
extern const char *__hostalias(const char *);
extern const char *_res_hostalias(const char *, char *, size_t);
/*
* Formulate a normal query, send, and await answer.
@ -2418,6 +2418,7 @@ res_searchN(name, target)
u_int dots;
int trailing_dot, ret, saved_herrno;
int got_nodata = 0, got_servfail = 0, tried_as_is = 0;
char abuf[MAXDNAME];
if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
h_errno = NETDB_INTERNAL;
@ -2436,7 +2437,7 @@ res_searchN(name, target)
/*
* if there aren't any dots, it could be a user-level alias
*/
if (!dots && (cp = __hostalias(name)) != NULL)
if (!dots && (cp = _res_hostalias(name, abuf, sizeof(abuf))) != NULL)
return (res_queryN(cp, target));
/*

View File

@ -96,6 +96,8 @@ static char *host_aliases[MAXALIASES];
static char hostbuf[8*1024];
static u_char host_addr[16]; /* IPv4 or IPv6 */
extern const char *_res_hostalias(const char *, char *, size_t);
#ifdef RESOLVSORT
static void addrsort(char **, int);
#endif
@ -477,6 +479,7 @@ _dns_gethostbyname(void *rval, void *cb_data, va_list ap)
const char *cp;
char *bp, *ep;
int n, size, type, len;
char abuf[MAXDNAME];
name = va_arg(ap, const char *);
af = va_arg(ap, int);
@ -510,7 +513,8 @@ _dns_gethostbyname(void *rval, void *cb_data, va_list ap)
* this is also done in res_query() since we are not the only
* function that looks up host names.
*/
if (!strchr(name, '.') && (cp = __hostalias(name)))
if (!strchr(name, '.') &&
(cp = _res_hostalias(name, abuf, sizeof abuf)))
name = cp;
/*

View File

@ -97,6 +97,8 @@ __FBSDID("$FreeBSD$");
#define MAXPACKET 1024
#endif
const char *_res_hostalias(const char *, char *, size_t);
/*
* Formulate a normal query, send, and await answer.
* Returned answer is placed in supplied buffer "answer".
@ -193,6 +195,7 @@ res_search(name, class, type, answer, anslen)
int anslen; /* size of answer */
{
const char *cp, * const *domain;
char tmp[MAXDNAME];
u_int dots;
int trailing_dot, ret, saved_herrno;
int got_nodata = 0, got_servfail = 0, tried_as_is = 0;
@ -211,7 +214,7 @@ res_search(name, class, type, answer, anslen)
trailing_dot++;
/* If there aren't any dots, it could be a user-level alias */
if (!dots && (cp = hostalias(name)) != NULL)
if (!dots && (cp = _res_hostalias(name, tmp, sizeof tmp)) != NULL)
return (res_query(cp, class, type, answer, anslen));
/*
@ -384,14 +387,11 @@ res_querydomain(name, domain, class, type, answer, anslen)
}
const char *
hostalias(name)
const char *name;
_res_hostalias(const char *name, char *dst, size_t siz)
{
char *cp1, *cp2;
FILE *fp;
char *file;
char *file, *cp1, *cp2;
char buf[BUFSIZ];
static char abuf[MAXDNAME];
FILE *fp;
if (_res.options & RES_NOALIASES)
return (NULL);
@ -413,18 +413,28 @@ hostalias(name)
;
if (!*cp1)
break;
for (cp2 = cp1 + 1; *cp2 && !isspace((unsigned char)*cp2); ++cp2)
for (cp2 = cp1 + 1; *cp2 &&
!isspace((unsigned char)*cp2); ++cp2)
;
abuf[sizeof(abuf) - 1] = *cp2 = '\0';
strncpy(abuf, cp1, sizeof(abuf) - 1);
*cp2 = '\0';
strncpy(dst, cp1, siz - 1);
dst[siz - 1] = '\0';
fclose(fp);
return (abuf);
return (dst);
}
}
fclose(fp);
return (NULL);
}
const char *
hostalias(const char *name)
{
static char abuf[MAXDNAME];
return (_res_hostalias(name, abuf, sizeof abuf));
}
/*
* Weak aliases for applications that use certain private entry points,
* and fail to include <resolv.h>.