Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-1-6]: src/dist/bind/bin/nslookup Pull up revision 1.3 (requested ...
details: https://anonhg.NetBSD.org/src/rev/65c964a9bafc
branches: netbsd-1-6
changeset: 528159:65c964a9bafc
user: lukem <lukem%NetBSD.org@localhost>
date: Fri Jun 28 11:36:31 2002 +0000
description:
Pull up revision 1.3 (requested by itojun in ticket #387):
Update to BIND 8.3.3. Fixes buffer overrun in resolver code.
diffstat:
dist/bind/bin/nslookup/list.c | 89 ++++++++++--
dist/bind/bin/nslookup/main.c | 287 +++++++++++++++++++++++++++++------------
2 files changed, 269 insertions(+), 107 deletions(-)
diffs (truncated from 694 to 300 lines):
diff -r 541c1aad1f51 -r 65c964a9bafc dist/bind/bin/nslookup/list.c
--- a/dist/bind/bin/nslookup/list.c Fri Jun 28 11:36:22 2002 +0000
+++ b/dist/bind/bin/nslookup/list.c Fri Jun 28 11:36:31 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: list.c,v 1.2 2001/01/27 07:22:01 itojun Exp $ */
+/* $NetBSD: list.c,v 1.2.2.1 2002/06/28 11:36:31 lukem Exp $ */
/*
* Copyright (c) 1985, 1989
@@ -55,7 +55,7 @@
#ifndef lint
static const char sccsid[] = "@(#)list.c 5.23 (Berkeley) 3/21/91";
-static const char rcsid[] = "Id: list.c,v 8.25 2000/12/23 08:14:46 vixie Exp";
+static const char rcsid[] = "Id: list.c,v 8.27 2002/04/09 05:55:17 marka Exp";
#endif /* not lint */
/*
@@ -260,7 +260,9 @@
ns_msg handle;
querybuf buf;
- struct sockaddr_in sin;
+ struct sockaddr_storage sa;
+ struct sockaddr_in *sin;
+ struct sockaddr_in6 *sin6;
HEADER *headerPtr;
int msglen, amtToRead, numRead, soacnt;
u_int len;
@@ -271,6 +273,8 @@
enum { NO_ERRORS, ERR_READING_LEN, ERR_READING_MSG, ERR_PRINTING }
error = NO_ERRORS;
struct iovec iov[2];
+ AddrInfo *AddrPtr;
+ int salen = 0;
/*
* Create a query packet for the requested domain name.
@@ -283,10 +287,6 @@
return (ERROR);
}
- memset(&sin, 0, sizeof sin);
- sin.sin_family = AF_INET;
- sin.sin_port = htons(nsport);
-
/*
* Check to see if we have the address of the server or the
* address of a server who knows about this domain.
@@ -295,20 +295,44 @@
*/
if (defaultPtr->addrList != NULL)
- sin.sin_addr = *(struct in_addr *) defaultPtr->addrList[0];
+ AddrPtr = defaultPtr->addrList[0];
else
- sin.sin_addr = *(struct in_addr *)
- defaultPtr->servers[0]->addrList[0];
+ AddrPtr = defaultPtr->servers[0]->addrList[0];
+
+ memset(&sa, 0, sizeof sa);
+ switch (AddrPtr->addrType) {
+ case AF_INET:
+ sin = (struct sockaddr_in *)&sa;
+ sin->sin_family = AddrPtr->addrType;
+ sin->sin_port = htons(nsport);
+ memcpy(&sin->sin_addr, AddrPtr->addr, AddrPtr->addrLen);
+#ifdef HAVE_SA_LEN
+ sin->sin_len = sizeof(*sin);
+#endif
+ salen = sizeof(struct sockaddr_in);
+ break;
+
+ case AF_INET6:
+ sin6 = (struct sockaddr_in6 *)&sa;
+ sin6->sin6_family = AddrPtr->addrType;
+ sin6->sin6_port = htons(nsport);
+ memcpy(&sin6->sin6_addr, AddrPtr->addr, AddrPtr->addrLen);
+#ifdef HAVE_SA_LEN
+ sin6->sin6_len = sizeof(*sin6);
+#endif
+ salen = sizeof(struct sockaddr_in6);
+ break;
+ }
/*
* Set up a virtual circuit to the server.
*/
- sockFD = socket(AF_INET, SOCK_STREAM, 0);
+ sockFD = socket(AddrPtr->addrType, SOCK_STREAM, 0);
if (sockFD < 0) {
perror("ls: socket");
return (ERROR);
}
- if (connect(sockFD, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
+ if (connect(sockFD, (struct sockaddr *)&sa, salen) < 0) {
int e;
if (errno == ECONNREFUSED)
@@ -436,7 +460,7 @@
strcpy(origin, name);
strcpy(name_ctx, "@");
}
- if (qtype == T_ANY || ns_rr_type(rr) == qtype) {
+ if (qtype == T_ANY || (int)ns_rr_type(rr) == qtype) {
if (ns_sprintrr(&handle, &rr, name_ctx, origin,
buf, sizeof buf) < 0) {
perror("ns_sprintrr");
@@ -532,13 +556,16 @@
int putToFile;
{
struct servent *sp;
- struct sockaddr_in sin;
+ struct sockaddr_storage sa;
+ struct sockaddr_in *sin;
+ struct sockaddr_in6 *sin6;
FILE *f;
int c;
int lastc;
char name[NAME_LEN];
char file[PATH_MAX];
int i;
+ int salen = 0;
/*
* We need a valid current host info to get an inet address.
@@ -575,23 +602,45 @@
return (ERROR);
}
- memset(&sin, 0, sizeof sin);
- sin.sin_family = curHostInfo.addrType;
- sin.sin_port = sp->s_port;
- memcpy(&sin.sin_addr, curHostInfo.addrList[0], curHostInfo.addrLen);
+ memset(&sa, 0, sizeof sa);
+ switch (curHostInfo.addrList[0]->addrType) {
+ case AF_INET:
+ sin = (struct sockaddr_in *)&sa;
+ sin->sin_family = curHostInfo.addrList[0]->addrType;
+ sin->sin_port = sp->s_port;
+ memcpy(&sin->sin_addr, curHostInfo.addrList[0]->addr,
+ curHostInfo.addrList[0]->addrLen);
+#ifdef HAVE_SA_LEN
+ sin->sin_len = sizeof(*sin);
+#endif
+ salen = sizeof(struct sockaddr_in);
+ break;
+
+ case AF_INET6:
+ sin6 = (struct sockaddr_in6 *)&sa;
+ sin6->sin6_family = curHostInfo.addrList[0]->addrType;
+ sin6->sin6_port = sp->s_port;
+ memcpy(&sin6->sin6_addr, curHostInfo.addrList[0]->addr,
+ curHostInfo.addrList[0]->addrLen);
+#ifdef HAVE_SA_LEN
+ sin6->sin6_len = sizeof(*sin6);
+#endif
+ salen = sizeof(struct sockaddr_in6);
+ break;
+ }
/*
* Set up a virtual circuit to the host.
*/
- sockFD = socket(curHostInfo.addrType, SOCK_STREAM, 0);
+ sockFD = socket(curHostInfo.addrList[0]->addrType, SOCK_STREAM, 0);
if (sockFD < 0) {
fflush(stdout);
perror("finger: socket");
return (ERROR);
}
- if (connect(sockFD, (struct sockaddr *)&sin, sizeof (sin)) < 0) {
+ if (connect(sockFD, (struct sockaddr *)&sa, salen) < 0) {
fflush(stdout);
perror("finger: connect");
close(sockFD);
diff -r 541c1aad1f51 -r 65c964a9bafc dist/bind/bin/nslookup/main.c
--- a/dist/bind/bin/nslookup/main.c Fri Jun 28 11:36:22 2002 +0000
+++ b/dist/bind/bin/nslookup/main.c Fri Jun 28 11:36:31 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.2 2001/01/27 07:22:01 itojun Exp $ */
+/* $NetBSD: main.c,v 1.2.2.1 2002/06/28 11:36:41 lukem Exp $ */
/*
* Copyright (c) 1985, 1989
@@ -79,7 +79,7 @@
#ifndef lint
static const char sccsid[] = "@(#)main.c 5.42 (Berkeley) 3/3/91";
-static const char rcsid[] = "Id: main.c,v 8.16 2000/12/23 08:14:47 vixie Exp";
+static const char rcsid[] = "Id: main.c,v 8.24 2002/05/26 03:12:20 marka Exp";
#endif /* not lint */
/*
@@ -110,7 +110,6 @@
#include <errno.h>
#include <limits.h>
#include <netdb.h>
-#include <resolv.h>
#include <setjmp.h>
#include <signal.h>
#include <stdio.h>
@@ -120,6 +119,8 @@
#include "port_after.h"
+#include <resolv.h>
+
#include "res.h"
#include "pathnames.h"
@@ -156,7 +157,7 @@
HostInfo *defaultPtr = NULL;
char defaultServer[NAME_LEN];
-struct in_addr defaultAddr;
+union res_sockaddr_union defaultAddr;
/*
@@ -170,7 +171,7 @@
* Stuff for Interrupt (control-C) signal handler.
*/
-extern SIG_FN IntrHandler();
+extern SIG_FN IntrHandler(int);
FILE *filePtr;
jmp_buf env;
@@ -178,10 +179,10 @@
/*
* Browser command for help.
*/
-char *pager;
+const char *pager;
-static void CvtAddrToPtr();
-static void ReadRC();
+static void CvtAddrToPtr(char *name);
+static void ReadRC(void);
/*
* Forward declarations.
@@ -190,6 +191,32 @@
static void res_re_init(void);
static void res_dnsrch(char *cp);
static void Usage(void);
+static void ShowOptions(void);
+
+static void
+UnionFromAddr(union res_sockaddr_union *u, int family, void *addr) {
+ memset(u, 0, sizeof *u);
+ switch (family) {
+ case AF_INET:
+ u->sin.sin_family = AF_INET;
+ u->sin.sin_port = htons(nsport);
+ memcpy(&u->sin.sin_addr, addr, 4);
+#ifdef HAVE_SA_LEN
+ u->sin.sin_len = sizeof(u->sin);
+#endif
+ break;
+ case AF_INET6:
+ u->sin6.sin6_family = AF_INET6;
+ u->sin6.sin6_port = htons(nsport);
+ memcpy(&u->sin6.sin6_addr, addr, 16);
+#ifdef HAVE_SA_LEN
+ u->sin6.sin6_len = sizeof(u->sin6);
+#endif
+ break;
+ default:
+ abort();
+ }
+}
/*
******************************************************************************
@@ -209,7 +236,6 @@
Boolean useLocalServer;
int result;
int i;
- struct hostent *hp;
/*
* Initialize the resolver library routines.
@@ -265,30 +291,38 @@
useLocalServer = FALSE;
if (argc == 2) {
- struct in_addr addr;
+ int nscount = 0;
+ union res_sockaddr_union u[MAXNS];
+ struct addrinfo *answer = NULL;
+ struct addrinfo *cur = NULL;
+ struct addrinfo hint;
/*
* Use an explicit name server. If the hostname lookup fails,
* default to the server(s) in resolv.conf.
Home |
Main Index |
Thread Index |
Old Index