diff options
author | ume <ume@FreeBSD.org> | 2002-10-03 17:25:33 +0000 |
---|---|---|
committer | ume <ume@FreeBSD.org> | 2002-10-03 17:25:33 +0000 |
commit | 6448ec6d62b52795cd96af767b261ed044ee49e1 (patch) | |
tree | 4d491ef356de870250c07cc6c7578be68ff3d9b1 /lib/libc/net/gethostbydns.c | |
parent | 84d13cfde442f981f1c7b8a8a95f8afa4e8e951e (diff) | |
download | FreeBSD-src-6448ec6d62b52795cd96af767b261ed044ee49e1.zip FreeBSD-src-6448ec6d62b52795cd96af767b261ed044ee49e1.tar.gz |
Allocate 64K recieve buffer for DNS responses.
Though res_query.c also defines and refers MAXPACKET, it is not
related to ansbuf. So, I didn't touch res_query.c.
Diffstat (limited to 'lib/libc/net/gethostbydns.c')
-rw-r--r-- | lib/libc/net/gethostbydns.c | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/lib/libc/net/gethostbydns.c b/lib/libc/net/gethostbydns.c index 0effbe4..d55ea89 100644 --- a/lib/libc/net/gethostbydns.c +++ b/lib/libc/net/gethostbydns.c @@ -68,6 +68,7 @@ __FBSDID("$FreeBSD$"); #include <arpa/nameser.h> #include <stdio.h> +#include <stdlib.h> #include <unistd.h> #include <string.h> #include <netdb.h> @@ -103,11 +104,7 @@ static void addrsort(char **, int); static void dprintf(char *, int) __printflike(1, 0); #endif -#if PACKETSZ > 1024 -#define MAXPACKET PACKETSZ -#else -#define MAXPACKET 1024 -#endif +#define MAXPACKET (64*1024) typedef union { HEADER hdr; @@ -477,7 +474,7 @@ _dns_gethostbyname(void *rval, void *cb_data, va_list ap) { const char *name; int af; - querybuf buf; + querybuf *buf; const char *cp; char *bp, *ep; int n, size, type, len; @@ -587,15 +584,22 @@ _dns_gethostbyname(void *rval, void *cb_data, va_list ap) break; } - n = res_search(name, C_IN, type, buf.buf, sizeof(buf.buf)); + if ((buf = malloc(sizeof(*buf))) == NULL) { + h_errno = NETDB_INTERNAL; + return NS_NOTFOUND; + } + n = res_search(name, C_IN, type, buf->buf, sizeof(buf->buf)); if (n < 0) { + free(buf); dprintf("res_search failed (%d)\n", n); return (NULL); - } else if (n > sizeof(buf.buf)) { + } else if (n > sizeof(buf->buf)) { + free(buf); dprintf("static buffer is too small (%d)\n", n); return (NULL); } - *(struct hostent **)rval = gethostanswer(&buf, n, name, type); + *(struct hostent **)rval = gethostanswer(buf, n, name, type); + free(buf); return (*(struct hostent **)rval != NULL) ? NS_SUCCESS : NS_NOTFOUND; } @@ -608,7 +612,7 @@ _dns_gethostbyaddr(void *rval, void *cb_data, va_list ap) static const u_char mapped[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0xff,0xff }; static const u_char tunnelled[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 }; int n, size; - querybuf buf; + querybuf *buf; struct hostent *hp; char qbuf[MAXDNAME+1], *qp; #ifdef SUNSECURITY @@ -675,17 +679,26 @@ _dns_gethostbyaddr(void *rval, void *cb_data, va_list ap) default: abort(); } - n = res_query(qbuf, C_IN, T_PTR, (u_char *)buf.buf, sizeof buf.buf); + if ((buf = malloc(sizeof(*buf))) == NULL) { + h_errno = NETDB_INTERNAL; + return NS_NOTFOUND; + } + n = res_query(qbuf, C_IN, T_PTR, (u_char *)buf->buf, sizeof buf->buf); if (n < 0) { + free(buf); dprintf("res_query failed (%d)\n", n); return NS_UNAVAIL; } - if (n > sizeof buf.buf) { + if (n > sizeof buf->buf) { + free(buf); dprintf("static buffer is too small (%d)\n", n); return NS_UNAVAIL; } - if (!(hp = gethostanswer(&buf, n, qbuf, T_PTR))) + if (!(hp = gethostanswer(buf, n, qbuf, T_PTR))) { + free(buf); return NS_NOTFOUND; /* h_errno was set by gethostanswer() */ + } + free(buf); #ifdef SUNSECURITY if (af == AF_INET) { /* |