diff options
author | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2002-08-27 08:53:14 +0000 |
---|---|---|
committer | Jun-ichiro itojun Hagino <itojun@cvs.openbsd.org> | 2002-08-27 08:53:14 +0000 |
commit | 3bbc9765b411ebbfdd17dc152a93daa0062258f7 (patch) | |
tree | 0992cec1ba1081f69f80aa729b58e5ee6bb75c00 /lib/libc | |
parent | 843511e4b1b10b69e36f2c6ead244ffce9af7fba (diff) |
allocate 64K recieve buffer for DNS responses.
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/net/getaddrinfo.c | 51 | ||||
-rw-r--r-- | lib/libc/net/gethostnamadr.c | 38 | ||||
-rw-r--r-- | lib/libc/net/getnetnamadr.c | 37 |
3 files changed, 78 insertions, 48 deletions
diff --git a/lib/libc/net/getaddrinfo.c b/lib/libc/net/getaddrinfo.c index db15e62668a..915286a404b 100644 --- a/lib/libc/net/getaddrinfo.c +++ b/lib/libc/net/getaddrinfo.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getaddrinfo.c,v 1.42 2002/08/22 16:35:37 itojun Exp $ */ +/* $OpenBSD: getaddrinfo.c,v 1.43 2002/08/27 08:53:13 itojun Exp $ */ /* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ /* @@ -181,11 +181,7 @@ static const struct explore explore[] = { #define PTON_MAX 4 #endif -#if PACKETSZ > 1024 -#define MAXPACKET PACKETSZ -#else -#define MAXPACKET 1024 -#endif +#define MAXPACKET (64*1024) typedef union { HEADER hdr; @@ -1230,7 +1226,7 @@ _dns_getaddrinfo(name, pai) const struct addrinfo *pai; { struct addrinfo *ai; - querybuf buf, buf2; + querybuf *buf, *buf2; struct addrinfo sentinel, *cur; struct res_target q, q2; @@ -1239,47 +1235,66 @@ _dns_getaddrinfo(name, pai) memset(&sentinel, 0, sizeof(sentinel)); cur = &sentinel; + buf = malloc(sizeof(*buf)); + if (buf == NULL) { + h_errno = NETDB_INTERNAL; + return NULL; + } + buf2 = malloc(sizeof(*buf2)); + if (buf2 == NULL) { + free(buf); + h_errno = NETDB_INTERNAL; + return NULL; + } + switch (pai->ai_family) { case AF_UNSPEC: /* prefer IPv6 */ q.qclass = C_IN; q.qtype = T_AAAA; - q.answer = buf.buf; - q.anslen = sizeof(buf); + q.answer = buf->buf; + q.anslen = sizeof(buf->buf); q.next = &q2; q2.qclass = C_IN; q2.qtype = T_A; - q2.answer = buf2.buf; - q2.anslen = sizeof(buf2); + q2.answer = buf2->buf; + q2.anslen = sizeof(buf2->buf); break; case AF_INET: q.qclass = C_IN; q.qtype = T_A; - q.answer = buf.buf; - q.anslen = sizeof(buf); + q.answer = buf->buf; + q.anslen = sizeof(buf->buf); break; case AF_INET6: q.qclass = C_IN; q.qtype = T_AAAA; - q.answer = buf.buf; - q.anslen = sizeof(buf); + q.answer = buf->buf; + q.anslen = sizeof(buf->buf); break; default: + free(buf); + free(buf2); return NULL; } - if (res_searchN(name, &q) < 0) + if (res_searchN(name, &q) < 0) { + free(buf); + free(buf2); return NULL; - ai = getanswer(&buf, q.n, q.name, q.qtype, pai); + } + ai = getanswer(buf, q.n, q.name, q.qtype, pai); if (ai) { cur->ai_next = ai; while (cur && cur->ai_next) cur = cur->ai_next; } if (q.next) { - ai = getanswer(&buf2, q2.n, q2.name, q2.qtype, pai); + ai = getanswer(buf2, q2.n, q2.name, q2.qtype, pai); if (ai) cur->ai_next = ai; } + free(buf); + free(buf2); return sentinel.ai_next; } diff --git a/lib/libc/net/gethostnamadr.c b/lib/libc/net/gethostnamadr.c index 3ac5049e72c..909ce573b73 100644 --- a/lib/libc/net/gethostnamadr.c +++ b/lib/libc/net/gethostnamadr.c @@ -52,7 +52,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.52 2002/08/22 16:35:37 itojun Exp $"; +static char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.53 2002/08/27 08:53:13 itojun Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -110,11 +110,7 @@ int _hokchar(const char *); static const char AskedForGot[] = "gethostby*.getanswer: asked for \"%s\", got \"%s\""; -#if PACKETSZ > 1024 -#define MAXPACKET PACKETSZ -#else -#define MAXPACKET 1024 -#endif +#define MAXPACKET (64*1024) typedef union { HEADER hdr; @@ -517,7 +513,7 @@ gethostbyname2(name, af) const char *name; int af; { - querybuf buf; + querybuf *buf; register const char *cp; char *bp, *ep; int n, size, type, i; @@ -635,15 +631,20 @@ gethostbyname2(name, af) break; #endif case 'b': - if ((n = res_search(name, C_IN, type, buf.buf, - sizeof(buf))) < 0) { + buf = malloc(sizeof(*buf)); + if (buf == NULL) + break; + if ((n = res_search(name, C_IN, type, buf->buf, + sizeof(buf->buf))) < 0) { + free(buf); #ifdef DEBUG if (_res.options & RES_DEBUG) printf("res_search failed\n"); #endif break; } - hp = getanswer(&buf, n, name, type); + hp = getanswer(buf, n, name, type); + free(buf); break; case 'f': hp = _gethtbyname2(name, af); @@ -661,7 +662,7 @@ gethostbyaddr(addr, len, af) { const u_char *uaddr = (const u_char *)addr; int n, size, i; - querybuf buf; + querybuf *buf; register struct hostent *hp; char qbuf[MAXDNAME+1], *qp; extern struct hostent *_gethtbyaddr(), *_yp_gethtbyaddr(); @@ -741,22 +742,29 @@ gethostbyaddr(addr, len, af) case 'b': if (af == AF_INET6) strcpy(qp, "ip6.arpa"); - n = res_query(qbuf, C_IN, T_PTR, (u_char *)buf.buf, - sizeof buf.buf); + buf = malloc(sizeof(*buf)); + if (!buf) + break; + n = res_query(qbuf, C_IN, T_PTR, buf->buf, + sizeof(buf->buf)); if (n < 0 && af == AF_INET6) { strcpy(qp, "ip6.int"); n = res_query(qbuf, C_IN, T_PTR, - (u_char *)buf.buf, sizeof buf.buf); + buf->buf, sizeof(buf->buf)); } if (n < 0) { + free(buf); #ifdef DEBUG if (_res.options & RES_DEBUG) printf("res_query failed\n"); #endif break; } - if (!(hp = getanswer(&buf, n, qbuf, T_PTR))) + if (!(hp = getanswer(buf, n, qbuf, T_PTR))) { + free(buf); break; + } + free(buf); hp->h_addrtype = af; hp->h_length = len; bcopy(addr, host_addr, len); diff --git a/lib/libc/net/getnetnamadr.c b/lib/libc/net/getnetnamadr.c index 44810337bde..abbfdbd64c2 100644 --- a/lib/libc/net/getnetnamadr.c +++ b/lib/libc/net/getnetnamadr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: getnetnamadr.c,v 1.17 2002/07/25 21:13:45 deraadt Exp $ */ +/* $OpenBSD: getnetnamadr.c,v 1.18 2002/08/27 08:53:13 itojun Exp $ */ /* * Copyright (c) 1997, Jason Downs. All rights reserved. @@ -77,7 +77,7 @@ static char sccsid[] = "@(#)getnetbyaddr.c 8.1 (Berkeley) 6/4/93"; static char sccsid_[] = "from getnetnamadr.c 1.4 (Coimbra) 93/06/03"; static char rcsid[] = "$From: getnetnamadr.c,v 8.7 1996/08/05 08:31:35 vixie Exp $"; #else -static char rcsid[] = "$OpenBSD: getnetnamadr.c,v 1.17 2002/07/25 21:13:45 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: getnetnamadr.c,v 1.18 2002/08/27 08:53:13 itojun Exp $"; #endif #endif /* LIBC_SCCS and not lint */ @@ -94,6 +94,7 @@ static char rcsid[] = "$OpenBSD: getnetnamadr.c,v 1.17 2002/07/25 21:13:45 deraa #include <ctype.h> #include <errno.h> #include <string.h> +#include <stdlib.h> extern int h_errno; @@ -106,11 +107,7 @@ int _hokchar(const char *); #define BYNAME 1 #define MAXALIASES 35 -#if PACKETSZ > 1024 -#define MAXPACKET PACKETSZ -#else -#define MAXPACKET 1024 -#endif +#define MAXPACKET (64*1024) typedef union { HEADER hdr; @@ -252,7 +249,7 @@ getnetbyaddr(net, net_type) { unsigned int netbr[4]; int nn, anslen; - querybuf buf; + querybuf *buf; char qbuf[MAXDNAME]; in_addr_t net2; struct netent *net_entry = NULL; @@ -300,16 +297,21 @@ getnetbyaddr(net, net_type) netbr[3], netbr[2], netbr[1], netbr[0]); break; } - anslen = res_query(qbuf, C_IN, T_PTR, (u_char *)&buf, - sizeof(buf)); + buf = malloc(sizeof(*buf)); + if (buf == NULL) + break; + anslen = res_query(qbuf, C_IN, T_PTR, buf->buf, + sizeof(buf->buf)); if (anslen < 0) { + free(buf); #ifdef DEBUG if (_res.options & RES_DEBUG) printf("res_query failed\n"); #endif break; } - net_entry = getnetanswer(&buf, anslen, BYADDR); + net_entry = getnetanswer(buf, anslen, BYADDR); + free(buf); if (net_entry != NULL) { unsigned u_net = net; /* maybe net should be unsigned ? */ @@ -336,7 +338,7 @@ getnetbyname(net) register const char *net; { int anslen; - querybuf buf; + querybuf *buf; char qbuf[MAXDNAME]; struct netent *net_entry = NULL; char lookups[MAXDNSLUS]; @@ -358,16 +360,21 @@ getnetbyname(net) #endif /* YP */ case 'b': strlcpy(qbuf, net, sizeof qbuf); - anslen = res_search(qbuf, C_IN, T_PTR, (u_char *)&buf, - sizeof(buf)); + buf = malloc(sizeof(*buf)); + if (buf == NULL) + break; + anslen = res_search(qbuf, C_IN, T_PTR, buf->buf, + sizeof(buf->buf)); if (anslen < 0) { + free(buf); #ifdef DEBUG if (_res.options & RES_DEBUG) printf("res_query failed\n"); #endif break; } - net_entry = getnetanswer(&buf, anslen, BYNAME); + net_entry = getnetanswer(buf, anslen, BYNAME); + free(buf); if (net_entry != NULL) return (net_entry); break; |