Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/net do not assume that nsaddr_list[n].sa_len is pro...
details: https://anonhg.NetBSD.org/src/rev/223d9d92593a
branches: trunk
changeset: 488120:223d9d92593a
user: itojun <itojun%NetBSD.org@localhost>
date: Sun Jun 18 21:41:23 2000 +0000
description:
do not assume that nsaddr_list[n].sa_len is properly initialized,
there can be some third-party code that does not.
diffstat:
lib/libc/net/res_init.c | 6 +++---
lib/libc/net/res_send.c | 41 +++++++++++++++++++++++------------------
2 files changed, 26 insertions(+), 21 deletions(-)
diffs (123 lines):
diff -r b5cd8153f7bc -r 223d9d92593a lib/libc/net/res_init.c
--- a/lib/libc/net/res_init.c Sun Jun 18 20:30:26 2000 +0000
+++ b/lib/libc/net/res_init.c Sun Jun 18 21:41:23 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: res_init.c,v 1.32 2000/04/25 13:57:08 itojun Exp $ */
+/* $NetBSD: res_init.c,v 1.33 2000/06/18 21:41:23 itojun Exp $ */
/*-
* Copyright (c) 1985, 1989, 1993
@@ -59,7 +59,7 @@
static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93";
static char rcsid[] = "Id: res_init.c,v 8.8 1997/06/01 20:34:37 vixie Exp ";
#else
-__RCSID("$NetBSD: res_init.c,v 1.32 2000/04/25 13:57:08 itojun Exp $");
+__RCSID("$NetBSD: res_init.c,v 1.33 2000/06/18 21:41:23 itojun Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -188,9 +188,9 @@
#else
_res.nsaddr.sin_addr.s_addr = INADDR_ANY;
#endif
- _res.nsaddr.sin_len = sizeof(struct sockaddr_in);
_res.nsaddr.sin_family = AF_INET;
_res.nsaddr.sin_port = htons(NAMESERVER_PORT);
+ _res.nsaddr.sin_len = sizeof(struct sockaddr_in);
#ifdef INET6
if (sizeof(_res_ext.nsaddr) >= _res.nsaddr.sin_len)
memcpy(&_res_ext.nsaddr, &_res.nsaddr, _res.nsaddr.sin_len);
diff -r b5cd8153f7bc -r 223d9d92593a lib/libc/net/res_send.c
--- a/lib/libc/net/res_send.c Sun Jun 18 20:30:26 2000 +0000
+++ b/lib/libc/net/res_send.c Sun Jun 18 21:41:23 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: res_send.c,v 1.28 2000/06/14 01:52:41 itojun Exp $ */
+/* $NetBSD: res_send.c,v 1.29 2000/06/18 21:41:23 itojun Exp $ */
/*-
* Copyright (c) 1985, 1989, 1993
@@ -59,7 +59,7 @@
static char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93";
static char rcsid[] = "Id: res_send.c,v 8.13 1997/06/01 20:34:37 vixie Exp ";
#else
-__RCSID("$NetBSD: res_send.c,v 1.28 2000/06/14 01:52:41 itojun Exp $");
+__RCSID("$NetBSD: res_send.c,v 1.29 2000/06/18 21:41:23 itojun Exp $");
#endif
#endif /* LIBC_SCCS and not lint */
@@ -410,6 +410,18 @@
for (try = 0; try < _res.retry; try++) {
for (ns = 0; ns < _res.nscount; ns++) {
struct sockaddr *nsap = get_nsaddr(ns);
+ socklen_t salen;
+
+ if (nsap->sa_len)
+ salen = nsap->sa_len;
+#ifdef INET6
+ else if (nsap->sa_family == AF_INET6)
+ salen = sizeof(struct sockaddr_in6);
+#endif
+ else if (nsap->sa_family == AF_INET)
+ salen = sizeof(struct sockaddr_in);
+ else
+ salen = 0; /* unknown, die on connect */
same_ns:
if (badns & (1 << ns)) {
@@ -449,9 +461,8 @@
}
Dprint((_res.options & RES_DEBUG) &&
- getnameinfo(nsap, (size_t)nsap->sa_len, abuf,
- sizeof(abuf), NULL, 0,
- NI_NUMERICHOST|NI_WITHSCOPEID) == 0,
+ getnameinfo(nsap, salen, abuf, sizeof(abuf),
+ NULL, 0, NI_NUMERICHOST | NI_WITHSCOPEID) == 0,
(stdout, ";; Querying server (# %d) address = %s\n",
ns + 1, abuf));
@@ -485,11 +496,10 @@
#endif
}
errno = 0;
- if (connect(s, (struct sockaddr *)(void *)nsap,
- (socklen_t)nsap->sa_len) < 0) {
+ if (connect(s, nsap, salen) < 0) {
terrno = errno;
Aerror(stderr, "connect/vc",
- errno, (struct sockaddr *)nsap);
+ errno, nsap);
badns |= (1 << ns);
res_close();
goto next_ns;
@@ -661,13 +671,10 @@
* receive a response from another server.
*/
if (!connected) {
- if (connect(s,
- (struct sockaddr *)(void *)nsap,
- (socklen_t)nsap->sa_len) < 0) {
+ if (connect(s, nsap, salen) < 0) {
Aerror(stderr,
"connect(dg)",
- errno,
- (struct sockaddr *)nsap);
+ errno, nsap);
badns |= (1 << ns);
res_close();
goto next_ns;
@@ -710,11 +717,9 @@
connected = 0;
errno = 0;
}
- if (sendto(s, buf, (size_t)buflen, 0,
- (struct sockaddr *)(void *)nsap,
- (socklen_t)nsap->sa_len) != buflen) {
- Aerror(stderr, "sendto", errno,
- (struct sockaddr *)nsap);
+ if (sendto(s, (char*)buf, buflen, 0,
+ nsap, salen) != buflen) {
+ Aerror(stderr, "sendto", errno, nsap);
badns |= (1 << ns);
res_close();
goto next_ns;
Home |
Main Index |
Thread Index |
Old Index