summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorume <ume@FreeBSD.org>2005-04-15 14:42:29 +0000
committerume <ume@FreeBSD.org>2005-04-15 14:42:29 +0000
commitb8a79c699c2858b875020bba30ca8ced2a6e3ed1 (patch)
tree31c9250817dd4dd9b5e307af8645d111e227d398 /lib
parent53377abba9839772973c53e13f0df4571c7da0c6 (diff)
downloadFreeBSD-src-b8a79c699c2858b875020bba30ca8ced2a6e3ed1.zip
FreeBSD-src-b8a79c699c2858b875020bba30ca8ced2a6e3ed1.tar.gz
hostalias() is not thread-safe. So, introduce _res_hostalias()
and use it. Obtained from: BIND9
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/net/getaddrinfo.c5
-rw-r--r--lib/libc/net/gethostbydns.c6
-rw-r--r--lib/libc/net/res_query.c32
3 files changed, 29 insertions, 14 deletions
diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c
index b695e58..8e7f566 100644
--- a/lib/libc/net/getaddrinfo.c
+++ b/lib/libc/net/getaddrinfo.c
@@ -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));
/*
diff --git a/lib/libc/net/gethostbydns.c b/lib/libc/net/gethostbydns.c
index 7dc405d..24de7ff 100644
--- a/lib/libc/net/gethostbydns.c
+++ b/lib/libc/net/gethostbydns.c
@@ -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;
/*
diff --git a/lib/libc/net/res_query.c b/lib/libc/net/res_query.c
index 68ac05c..4158f98 100644
--- a/lib/libc/net/res_query.c
+++ b/lib/libc/net/res_query.c
@@ -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>.
OpenPOWER on IntegriCloud