diff options
author | miod <> | 2002-09-09 18:25:08 +0000 |
---|---|---|
committer | miod <> | 2002-09-09 18:25:08 +0000 |
commit | 7261f561854c06635df68ed9ee974f7c2ef7bb64 (patch) | |
tree | a1d97e98b225ac6482665114a351840b316b3d40 /src/lib/libc/net | |
parent | 6a7c18df4395e35d088ea861903f549c2be52f20 (diff) | |
download | openbsd-7261f561854c06635df68ed9ee974f7c2ef7bb64.tar.gz openbsd-7261f561854c06635df68ed9ee974f7c2ef7bb64.tar.bz2 openbsd-7261f561854c06635df68ed9ee974f7c2ef7bb64.zip |
MFC (itojun):
allocate 64K receive buffer for DNS responses.
Diffstat (limited to 'src/lib/libc/net')
-rw-r--r-- | src/lib/libc/net/getaddrinfo.c | 51 | ||||
-rw-r--r-- | src/lib/libc/net/gethostnamadr.c | 36 | ||||
-rw-r--r-- | src/lib/libc/net/getnetnamadr.c | 37 |
3 files changed, 77 insertions, 47 deletions
diff --git a/src/lib/libc/net/getaddrinfo.c b/src/lib/libc/net/getaddrinfo.c index f9ba1e55d7..65898ef75a 100644 --- a/src/lib/libc/net/getaddrinfo.c +++ b/src/lib/libc/net/getaddrinfo.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: getaddrinfo.c,v 1.30 2001/08/20 02:23:05 itojun Exp $ */ | 1 | /* $OpenBSD: getaddrinfo.c,v 1.30.2.1 2002/09/09 18:25:08 miod Exp $ */ |
2 | /* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ | 2 | /* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ |
3 | 3 | ||
4 | /* | 4 | /* |
@@ -179,11 +179,7 @@ static const struct explore explore[] = { | |||
179 | #define PTON_MAX 4 | 179 | #define PTON_MAX 4 |
180 | #endif | 180 | #endif |
181 | 181 | ||
182 | #if PACKETSZ > 1024 | 182 | #define MAXPACKET (64*1024) |
183 | #define MAXPACKET PACKETSZ | ||
184 | #else | ||
185 | #define MAXPACKET 1024 | ||
186 | #endif | ||
187 | 183 | ||
188 | typedef union { | 184 | typedef union { |
189 | HEADER hdr; | 185 | HEADER hdr; |
@@ -1210,7 +1206,7 @@ _dns_getaddrinfo(name, pai) | |||
1210 | const struct addrinfo *pai; | 1206 | const struct addrinfo *pai; |
1211 | { | 1207 | { |
1212 | struct addrinfo *ai; | 1208 | struct addrinfo *ai; |
1213 | querybuf buf, buf2; | 1209 | querybuf *buf, *buf2; |
1214 | struct addrinfo sentinel, *cur; | 1210 | struct addrinfo sentinel, *cur; |
1215 | struct res_target q, q2; | 1211 | struct res_target q, q2; |
1216 | 1212 | ||
@@ -1219,47 +1215,66 @@ _dns_getaddrinfo(name, pai) | |||
1219 | memset(&sentinel, 0, sizeof(sentinel)); | 1215 | memset(&sentinel, 0, sizeof(sentinel)); |
1220 | cur = &sentinel; | 1216 | cur = &sentinel; |
1221 | 1217 | ||
1218 | buf = malloc(sizeof(*buf)); | ||
1219 | if (buf == NULL) { | ||
1220 | h_errno = NETDB_INTERNAL; | ||
1221 | return NULL; | ||
1222 | } | ||
1223 | buf2 = malloc(sizeof(*buf2)); | ||
1224 | if (buf2 == NULL) { | ||
1225 | free(buf); | ||
1226 | h_errno = NETDB_INTERNAL; | ||
1227 | return NULL; | ||
1228 | } | ||
1229 | |||
1222 | switch (pai->ai_family) { | 1230 | switch (pai->ai_family) { |
1223 | case AF_UNSPEC: | 1231 | case AF_UNSPEC: |
1224 | /* prefer IPv6 */ | 1232 | /* prefer IPv6 */ |
1225 | q.qclass = C_IN; | 1233 | q.qclass = C_IN; |
1226 | q.qtype = T_AAAA; | 1234 | q.qtype = T_AAAA; |
1227 | q.answer = buf.buf; | 1235 | q.answer = buf->buf; |
1228 | q.anslen = sizeof(buf); | 1236 | q.anslen = sizeof(buf->buf); |
1229 | q.next = &q2; | 1237 | q.next = &q2; |
1230 | q2.qclass = C_IN; | 1238 | q2.qclass = C_IN; |
1231 | q2.qtype = T_A; | 1239 | q2.qtype = T_A; |
1232 | q2.answer = buf2.buf; | 1240 | q2.answer = buf2->buf; |
1233 | q2.anslen = sizeof(buf2); | 1241 | q2.anslen = sizeof(buf2->buf); |
1234 | break; | 1242 | break; |
1235 | case AF_INET: | 1243 | case AF_INET: |
1236 | q.qclass = C_IN; | 1244 | q.qclass = C_IN; |
1237 | q.qtype = T_A; | 1245 | q.qtype = T_A; |
1238 | q.answer = buf.buf; | 1246 | q.answer = buf->buf; |
1239 | q.anslen = sizeof(buf); | 1247 | q.anslen = sizeof(buf->buf); |
1240 | break; | 1248 | break; |
1241 | case AF_INET6: | 1249 | case AF_INET6: |
1242 | q.qclass = C_IN; | 1250 | q.qclass = C_IN; |
1243 | q.qtype = T_AAAA; | 1251 | q.qtype = T_AAAA; |
1244 | q.answer = buf.buf; | 1252 | q.answer = buf->buf; |
1245 | q.anslen = sizeof(buf); | 1253 | q.anslen = sizeof(buf->buf); |
1246 | break; | 1254 | break; |
1247 | default: | 1255 | default: |
1256 | free(buf); | ||
1257 | free(buf2); | ||
1248 | return NULL; | 1258 | return NULL; |
1249 | } | 1259 | } |
1250 | if (res_searchN(name, &q) < 0) | 1260 | if (res_searchN(name, &q) < 0) { |
1261 | free(buf); | ||
1262 | free(buf2); | ||
1251 | return NULL; | 1263 | return NULL; |
1252 | ai = getanswer(&buf, q.n, q.name, q.qtype, pai); | 1264 | } |
1265 | ai = getanswer(buf, q.n, q.name, q.qtype, pai); | ||
1253 | if (ai) { | 1266 | if (ai) { |
1254 | cur->ai_next = ai; | 1267 | cur->ai_next = ai; |
1255 | while (cur && cur->ai_next) | 1268 | while (cur && cur->ai_next) |
1256 | cur = cur->ai_next; | 1269 | cur = cur->ai_next; |
1257 | } | 1270 | } |
1258 | if (q.next) { | 1271 | if (q.next) { |
1259 | ai = getanswer(&buf2, q2.n, q2.name, q2.qtype, pai); | 1272 | ai = getanswer(buf2, q2.n, q2.name, q2.qtype, pai); |
1260 | if (ai) | 1273 | if (ai) |
1261 | cur->ai_next = ai; | 1274 | cur->ai_next = ai; |
1262 | } | 1275 | } |
1276 | free(buf); | ||
1277 | free(buf2); | ||
1263 | return sentinel.ai_next; | 1278 | return sentinel.ai_next; |
1264 | } | 1279 | } |
1265 | 1280 | ||
diff --git a/src/lib/libc/net/gethostnamadr.c b/src/lib/libc/net/gethostnamadr.c index cb6e00d31a..2fdc3abdc4 100644 --- a/src/lib/libc/net/gethostnamadr.c +++ b/src/lib/libc/net/gethostnamadr.c | |||
@@ -52,7 +52,7 @@ | |||
52 | */ | 52 | */ |
53 | 53 | ||
54 | #if defined(LIBC_SCCS) && !defined(lint) | 54 | #if defined(LIBC_SCCS) && !defined(lint) |
55 | static char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.43.2.1 2002/06/26 06:03:31 millert Exp $"; | 55 | static char rcsid[] = "$OpenBSD: gethostnamadr.c,v 1.43.2.2 2002/09/09 18:25:08 miod Exp $"; |
56 | #endif /* LIBC_SCCS and not lint */ | 56 | #endif /* LIBC_SCCS and not lint */ |
57 | 57 | ||
58 | #include <sys/param.h> | 58 | #include <sys/param.h> |
@@ -110,11 +110,7 @@ int _hokchar __P((const char *)); | |||
110 | static const char AskedForGot[] = | 110 | static const char AskedForGot[] = |
111 | "gethostby*.getanswer: asked for \"%s\", got \"%s\""; | 111 | "gethostby*.getanswer: asked for \"%s\", got \"%s\""; |
112 | 112 | ||
113 | #if PACKETSZ > 1024 | 113 | #define MAXPACKET (64*1024) |
114 | #define MAXPACKET PACKETSZ | ||
115 | #else | ||
116 | #define MAXPACKET 1024 | ||
117 | #endif | ||
118 | 114 | ||
119 | typedef union { | 115 | typedef union { |
120 | HEADER hdr; | 116 | HEADER hdr; |
@@ -510,7 +506,7 @@ gethostbyname2(name, af) | |||
510 | const char *name; | 506 | const char *name; |
511 | int af; | 507 | int af; |
512 | { | 508 | { |
513 | querybuf buf; | 509 | querybuf *buf; |
514 | register const char *cp; | 510 | register const char *cp; |
515 | char *bp, *ep; | 511 | char *bp, *ep; |
516 | int n, size, type, i; | 512 | int n, size, type, i; |
@@ -628,15 +624,20 @@ gethostbyname2(name, af) | |||
628 | break; | 624 | break; |
629 | #endif | 625 | #endif |
630 | case 'b': | 626 | case 'b': |
631 | if ((n = res_search(name, C_IN, type, buf.buf, | 627 | buf = malloc(sizeof(*buf)); |
632 | sizeof(buf))) < 0) { | 628 | if (buf == NULL) |
629 | break; | ||
630 | if ((n = res_search(name, C_IN, type, buf->buf, | ||
631 | sizeof(buf->buf))) < 0) { | ||
632 | free(buf); | ||
633 | #ifdef DEBUG | 633 | #ifdef DEBUG |
634 | if (_res.options & RES_DEBUG) | 634 | if (_res.options & RES_DEBUG) |
635 | printf("res_search failed\n"); | 635 | printf("res_search failed\n"); |
636 | #endif | 636 | #endif |
637 | break; | 637 | break; |
638 | } | 638 | } |
639 | hp = getanswer(&buf, n, name, type); | 639 | hp = getanswer(buf, n, name, type); |
640 | free(buf); | ||
640 | break; | 641 | break; |
641 | case 'f': | 642 | case 'f': |
642 | hp = _gethtbyname2(name, af); | 643 | hp = _gethtbyname2(name, af); |
@@ -654,7 +655,7 @@ gethostbyaddr(addr, len, af) | |||
654 | { | 655 | { |
655 | const u_char *uaddr = (const u_char *)addr; | 656 | const u_char *uaddr = (const u_char *)addr; |
656 | int n, size, i; | 657 | int n, size, i; |
657 | querybuf buf; | 658 | querybuf *buf; |
658 | register struct hostent *hp; | 659 | register struct hostent *hp; |
659 | char qbuf[MAXDNAME+1], *qp; | 660 | char qbuf[MAXDNAME+1], *qp; |
660 | extern struct hostent *_gethtbyaddr(), *_yp_gethtbyaddr(); | 661 | extern struct hostent *_gethtbyaddr(), *_yp_gethtbyaddr(); |
@@ -730,17 +731,24 @@ gethostbyaddr(addr, len, af) | |||
730 | break; | 731 | break; |
731 | #endif | 732 | #endif |
732 | case 'b': | 733 | case 'b': |
733 | n = res_query(qbuf, C_IN, T_PTR, (u_char *)buf.buf, | 734 | buf = malloc(sizeof(*buf)); |
734 | sizeof buf.buf); | 735 | if (!buf) |
736 | break; | ||
737 | n = res_query(qbuf, C_IN, T_PTR, buf->buf, | ||
738 | sizeof(buf->buf)); | ||
735 | if (n < 0) { | 739 | if (n < 0) { |
740 | free(buf); | ||
736 | #ifdef DEBUG | 741 | #ifdef DEBUG |
737 | if (_res.options & RES_DEBUG) | 742 | if (_res.options & RES_DEBUG) |
738 | printf("res_query failed\n"); | 743 | printf("res_query failed\n"); |
739 | #endif | 744 | #endif |
740 | break; | 745 | break; |
741 | } | 746 | } |
742 | if (!(hp = getanswer(&buf, n, qbuf, T_PTR))) | 747 | if (!(hp = getanswer(buf, n, qbuf, T_PTR))) { |
748 | free(buf); | ||
743 | break; | 749 | break; |
750 | } | ||
751 | free(buf); | ||
744 | hp->h_addrtype = af; | 752 | hp->h_addrtype = af; |
745 | hp->h_length = len; | 753 | hp->h_length = len; |
746 | bcopy(addr, host_addr, len); | 754 | bcopy(addr, host_addr, len); |
diff --git a/src/lib/libc/net/getnetnamadr.c b/src/lib/libc/net/getnetnamadr.c index 685434791a..d3537be17f 100644 --- a/src/lib/libc/net/getnetnamadr.c +++ b/src/lib/libc/net/getnetnamadr.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: getnetnamadr.c,v 1.14.2.1 2002/06/26 06:03:31 millert Exp $ */ | 1 | /* $OpenBSD: getnetnamadr.c,v 1.14.2.2 2002/09/09 18:25:08 miod Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Copyright (c) 1997, Jason Downs. All rights reserved. | 4 | * Copyright (c) 1997, Jason Downs. All rights reserved. |
@@ -77,7 +77,7 @@ static char sccsid[] = "@(#)getnetbyaddr.c 8.1 (Berkeley) 6/4/93"; | |||
77 | static char sccsid_[] = "from getnetnamadr.c 1.4 (Coimbra) 93/06/03"; | 77 | static char sccsid_[] = "from getnetnamadr.c 1.4 (Coimbra) 93/06/03"; |
78 | static char rcsid[] = "$From: getnetnamadr.c,v 8.7 1996/08/05 08:31:35 vixie Exp $"; | 78 | static char rcsid[] = "$From: getnetnamadr.c,v 8.7 1996/08/05 08:31:35 vixie Exp $"; |
79 | #else | 79 | #else |
80 | static char rcsid[] = "$OpenBSD: getnetnamadr.c,v 1.14.2.1 2002/06/26 06:03:31 millert Exp $"; | 80 | static char rcsid[] = "$OpenBSD: getnetnamadr.c,v 1.14.2.2 2002/09/09 18:25:08 miod Exp $"; |
81 | #endif | 81 | #endif |
82 | #endif /* LIBC_SCCS and not lint */ | 82 | #endif /* LIBC_SCCS and not lint */ |
83 | 83 | ||
@@ -94,6 +94,7 @@ static char rcsid[] = "$OpenBSD: getnetnamadr.c,v 1.14.2.1 2002/06/26 06:03:31 m | |||
94 | #include <ctype.h> | 94 | #include <ctype.h> |
95 | #include <errno.h> | 95 | #include <errno.h> |
96 | #include <string.h> | 96 | #include <string.h> |
97 | #include <stdlib.h> | ||
97 | 98 | ||
98 | extern int h_errno; | 99 | extern int h_errno; |
99 | 100 | ||
@@ -106,11 +107,7 @@ int _hokchar __P((const char *)); | |||
106 | #define BYNAME 1 | 107 | #define BYNAME 1 |
107 | #define MAXALIASES 35 | 108 | #define MAXALIASES 35 |
108 | 109 | ||
109 | #if PACKETSZ > 1024 | 110 | #define MAXPACKET (64*1024) |
110 | #define MAXPACKET PACKETSZ | ||
111 | #else | ||
112 | #define MAXPACKET 1024 | ||
113 | #endif | ||
114 | 111 | ||
115 | typedef union { | 112 | typedef union { |
116 | HEADER hdr; | 113 | HEADER hdr; |
@@ -252,7 +249,7 @@ getnetbyaddr(net, net_type) | |||
252 | { | 249 | { |
253 | unsigned int netbr[4]; | 250 | unsigned int netbr[4]; |
254 | int nn, anslen; | 251 | int nn, anslen; |
255 | querybuf buf; | 252 | querybuf *buf; |
256 | char qbuf[MAXDNAME]; | 253 | char qbuf[MAXDNAME]; |
257 | in_addr_t net2; | 254 | in_addr_t net2; |
258 | struct netent *net_entry = NULL; | 255 | struct netent *net_entry = NULL; |
@@ -300,16 +297,21 @@ getnetbyaddr(net, net_type) | |||
300 | netbr[3], netbr[2], netbr[1], netbr[0]); | 297 | netbr[3], netbr[2], netbr[1], netbr[0]); |
301 | break; | 298 | break; |
302 | } | 299 | } |
303 | anslen = res_query(qbuf, C_IN, T_PTR, (u_char *)&buf, | 300 | buf = malloc(sizeof(*buf)); |
304 | sizeof(buf)); | 301 | if (buf == NULL) |
302 | break; | ||
303 | anslen = res_query(qbuf, C_IN, T_PTR, buf->buf, | ||
304 | sizeof(buf->buf)); | ||
305 | if (anslen < 0) { | 305 | if (anslen < 0) { |
306 | free(buf); | ||
306 | #ifdef DEBUG | 307 | #ifdef DEBUG |
307 | if (_res.options & RES_DEBUG) | 308 | if (_res.options & RES_DEBUG) |
308 | printf("res_query failed\n"); | 309 | printf("res_query failed\n"); |
309 | #endif | 310 | #endif |
310 | break; | 311 | break; |
311 | } | 312 | } |
312 | net_entry = getnetanswer(&buf, anslen, BYADDR); | 313 | net_entry = getnetanswer(buf, anslen, BYADDR); |
314 | free(buf); | ||
313 | if (net_entry != NULL) { | 315 | if (net_entry != NULL) { |
314 | unsigned u_net = net; /* maybe net should be unsigned ? */ | 316 | unsigned u_net = net; /* maybe net should be unsigned ? */ |
315 | 317 | ||
@@ -336,7 +338,7 @@ getnetbyname(net) | |||
336 | register const char *net; | 338 | register const char *net; |
337 | { | 339 | { |
338 | int anslen; | 340 | int anslen; |
339 | querybuf buf; | 341 | querybuf *buf; |
340 | char qbuf[MAXDNAME]; | 342 | char qbuf[MAXDNAME]; |
341 | struct netent *net_entry = NULL; | 343 | struct netent *net_entry = NULL; |
342 | char lookups[MAXDNSLUS]; | 344 | char lookups[MAXDNSLUS]; |
@@ -358,16 +360,21 @@ getnetbyname(net) | |||
358 | #endif /* YP */ | 360 | #endif /* YP */ |
359 | case 'b': | 361 | case 'b': |
360 | strlcpy(qbuf, net, sizeof qbuf); | 362 | strlcpy(qbuf, net, sizeof qbuf); |
361 | anslen = res_search(qbuf, C_IN, T_PTR, (u_char *)&buf, | 363 | buf = malloc(sizeof(*buf)); |
362 | sizeof(buf)); | 364 | if (buf == NULL) |
365 | break; | ||
366 | anslen = res_search(qbuf, C_IN, T_PTR, buf->buf, | ||
367 | sizeof(buf->buf)); | ||
363 | if (anslen < 0) { | 368 | if (anslen < 0) { |
369 | free(buf); | ||
364 | #ifdef DEBUG | 370 | #ifdef DEBUG |
365 | if (_res.options & RES_DEBUG) | 371 | if (_res.options & RES_DEBUG) |
366 | printf("res_query failed\n"); | 372 | printf("res_query failed\n"); |
367 | #endif | 373 | #endif |
368 | break; | 374 | break; |
369 | } | 375 | } |
370 | net_entry = getnetanswer(&buf, anslen, BYNAME); | 376 | net_entry = getnetanswer(buf, anslen, BYNAME); |
377 | free(buf); | ||
371 | if (net_entry != NULL) | 378 | if (net_entry != NULL) |
372 | return (net_entry); | 379 | return (net_entry); |
373 | break; | 380 | break; |