diff options
Diffstat (limited to 'lib/libc/net/getnetbydns.c')
-rw-r--r-- | lib/libc/net/getnetbydns.c | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/lib/libc/net/getnetbydns.c b/lib/libc/net/getnetbydns.c index 6e70ece..6b72c43 100644 --- a/lib/libc/net/getnetbydns.c +++ b/lib/libc/net/getnetbydns.c @@ -71,6 +71,7 @@ __FBSDID("$FreeBSD$"); #include <arpa/nameser.h> #include <stdio.h> +#include <stdlib.h> #include <netdb.h> #include <resolv.h> #include <ctype.h> @@ -88,11 +89,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; @@ -228,7 +225,7 @@ _dns_getnetbyaddr(void *rval, void *cb_data, va_list ap) int net_type; unsigned int netbr[4]; int nn, anslen; - querybuf buf; + querybuf *buf; char qbuf[MAXDNAME]; unsigned long net2; struct netent *net_entry; @@ -259,21 +256,28 @@ _dns_getnetbyaddr(void *rval, void *cb_data, va_list ap) 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 NS_NOTFOUND; + } + 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 NS_UNAVAIL; - } 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 NS_UNAVAIL; } - 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 ? */ @@ -292,7 +296,7 @@ _dns_getnetbyname(void *rval, void *cb_data, va_list ap) { const char *net; int anslen; - querybuf buf; + querybuf *buf; char qbuf[MAXDNAME]; net = va_arg(ap, const char *); @@ -303,23 +307,30 @@ _dns_getnetbyname(void *rval, void *cb_data, va_list ap) h_errno = NETDB_INTERNAL; return NS_UNAVAIL; } + if ((buf = malloc(sizeof(*buf))) == NULL) { + h_errno = NETDB_INTERNAL; + return NS_NOTFOUND; + } 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 NS_UNAVAIL; - } 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 NS_UNAVAIL; } - *(struct netent**)rval = getnetanswer(&buf, anslen, BYNAME); + *(struct netent**)rval = getnetanswer(buf, anslen, BYNAME); + free(buf); return (*(struct netent**)rval != NULL) ? NS_SUCCESS : NS_NOTFOUND; } |