summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/net/gethostbydns.c39
-rw-r--r--lib/libc/net/getnetbydns.c37
2 files changed, 50 insertions, 26 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) {
/*
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;
}
OpenPOWER on IntegriCloud