diff options
| author | Hajimu UMEMOTO <ume@FreeBSD.org> | 2002-10-23 14:45:25 +0000 |
|---|---|---|
| committer | Hajimu UMEMOTO <ume@FreeBSD.org> | 2002-10-23 14:45:25 +0000 |
| commit | 096d5f48a286b2ce73431f9be2f063240165c2b5 (patch) | |
| tree | c29375f02df20455425e83f206b671719dba91ce | |
| parent | fc0777fdfbd474c6355f79da025c2ca831e8beaf (diff) | |
Notes
| -rw-r--r-- | lib/libc/net/gethostbydns.c | 41 | ||||
| -rw-r--r-- | lib/libc/net/getnetbydns.c | 39 |
2 files changed, 54 insertions, 26 deletions
diff --git a/lib/libc/net/gethostbydns.c b/lib/libc/net/gethostbydns.c index 8b1fd50989a5..d0907c9d8022 100644 --- a/lib/libc/net/gethostbydns.c +++ b/lib/libc/net/gethostbydns.c @@ -67,6 +67,7 @@ static char rcsid[] = "$FreeBSD$"; #include <arpa/nameser.h> #include <stdio.h> +#include <stdlib.h> #include <unistd.h> #include <string.h> #include <netdb.h> @@ -96,11 +97,7 @@ static u_char host_addr[16]; /* IPv4 or IPv6 */ static void addrsort __P((char **, int)); #endif -#if PACKETSZ > 1024 -#define MAXPACKET PACKETSZ -#else -#define MAXPACKET 1024 -#endif +#define MAXPACKET (64*1024) typedef union { HEADER hdr; @@ -480,10 +477,11 @@ _gethostbydnsname(name, af) const char *name; int af; { - querybuf buf; + querybuf *buf; register const char *cp; char *bp; int n, size, type, len; + struct hostent *hp; if ((_res.options & RES_INIT) == 0 && res_init() == -1) { h_errno = NETDB_INTERNAL; @@ -584,15 +582,23 @@ _gethostbydnsname(name, af) break; } - n = res_search(name, C_IN, type, buf.buf, sizeof(buf.buf)); + if ((buf = malloc(sizeof(*buf))) == NULL) { + h_errno = NETDB_INTERNAL; + return (NULL); + } + 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); } - return (gethostanswer(&buf, n, name, type)); + hp = gethostanswer(buf, n, name, type); + free(buf); + return (hp); } struct hostent * @@ -604,7 +610,7 @@ _gethostbydnsaddr(addr, len, af) 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; register struct hostent *hp; char qbuf[MAXDNAME+1], *qp; #ifdef SUNSECURITY @@ -664,17 +670,26 @@ _gethostbydnsaddr(addr, len, af) 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 (NULL); + } + 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 (NULL); } - if (n > sizeof buf.buf) { + if (n > sizeof buf->buf) { + free(buf); dprintf("static buffer is too small (%d)\n", n); return (NULL); } - if (!(hp = gethostanswer(&buf, n, qbuf, T_PTR))) + if (!(hp = gethostanswer(buf, n, qbuf, T_PTR))) { + free(buf); return (NULL); /* h_errno was set by gethostanswer() */ + } + free(buf); #ifdef SUNSECURITY if (af == AF_INET) { /* diff --git a/lib/libc/net/getnetbydns.c b/lib/libc/net/getnetbydns.c index 52b687a54246..a038bda5c7ec 100644 --- a/lib/libc/net/getnetbydns.c +++ b/lib/libc/net/getnetbydns.c @@ -70,6 +70,7 @@ static char rcsid[] = "$FreeBSD$"; #include <arpa/nameser.h> #include <stdio.h> +#include <stdlib.h> #include <netdb.h> #include <resolv.h> #include <ctype.h> @@ -85,11 +86,7 @@ extern int h_errno; #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; @@ -226,7 +223,7 @@ _getnetbydnsaddr(net, net_type) { unsigned int netbr[4]; int nn, anslen; - querybuf buf; + querybuf *buf; char qbuf[MAXDNAME]; unsigned long net2; struct netent *net_entry; @@ -252,21 +249,28 @@ _getnetbydnsaddr(net, net_type) netbr[1], netbr[0]); break; } - anslen = res_query(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf)); + if ((buf = malloc(sizeof(*buf))) == NULL) { + h_errno = NETDB_INTERNAL; + return (NULL); + } + anslen = res_query(qbuf, C_IN, T_PTR, (u_char *)buf, sizeof(*buf)); if (anslen < 0) { + free(buf); #ifdef DEBUG if (_res.options & RES_DEBUG) printf("res_search failed\n"); #endif return (NULL); - } else if (anslen > sizeof(buf)) { + } else if (anslen > sizeof(*buf)) { + free(buf); #ifdef DEBUG if (_res.options & RES_DEBUG) printf("res_search static buffer too small\n"); #endif return (NULL); } - net_entry = getnetanswer(&buf, anslen, BYADDR); + net_entry = getnetanswer(buf, anslen, BYADDR); + free(buf); if (net_entry) { unsigned u_net = net; /* maybe net should be unsigned ? */ @@ -284,30 +288,39 @@ _getnetbydnsname(net) register const char *net; { int anslen; - querybuf buf; + querybuf *buf; char qbuf[MAXDNAME]; + struct netent *net_entry; if ((_res.options & RES_INIT) == 0 && res_init() == -1) { h_errno = NETDB_INTERNAL; return (NULL); } + if ((buf = malloc(sizeof(*buf))) == NULL) { + h_errno = NETDB_INTERNAL; + return (NULL); + } strncpy(qbuf, net, sizeof(qbuf) - 1); qbuf[sizeof(qbuf) - 1] = '\0'; - anslen = res_search(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf)); + anslen = res_search(qbuf, C_IN, T_PTR, (u_char *)buf, sizeof(*buf)); if (anslen < 0) { + free(buf); #ifdef DEBUG if (_res.options & RES_DEBUG) printf("res_search failed\n"); #endif return (NULL); - } else if (anslen > sizeof(buf)) { + } else if (anslen > sizeof(*buf)) { + free(buf); #ifdef DEBUG if (_res.options & RES_DEBUG) printf("res_search static buffer too small\n"); #endif return (NULL); } - return getnetanswer(&buf, anslen, BYNAME); + net_entry = getnetanswer(buf, anslen, BYNAME); + free(buf); + return net_entry; } void |
