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.5 (requested ...
details: https://anonhg.NetBSD.org/src/rev/541c1aad1f51
branches: netbsd-1-6
changeset: 528158:541c1aad1f51
user: lukem <lukem%NetBSD.org@localhost>
date: Fri Jun 28 11:36:22 2002 +0000
description:
Pull up revision 1.5 (requested by itojun in ticket #387):
Update to BIND 8.3.3. Fixes buffer overrun in resolver code.
diffstat:
dist/bind/bin/nslookup/getinfo.c | 459 +++++++++++++++++++++++++++++---------
1 files changed, 344 insertions(+), 115 deletions(-)
diffs (truncated from 779 to 300 lines):
diff -r 1aaef5922ee2 -r 541c1aad1f51 dist/bind/bin/nslookup/getinfo.c
--- a/dist/bind/bin/nslookup/getinfo.c Fri Jun 28 11:36:12 2002 +0000
+++ b/dist/bind/bin/nslookup/getinfo.c Fri Jun 28 11:36:22 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: getinfo.c,v 1.4 2001/05/17 22:59:41 itojun Exp $ */
+/* $NetBSD: getinfo.c,v 1.4.2.1 2002/06/28 11:36:22 lukem Exp $ */
/*
* Copyright (c) 1985, 1989
@@ -55,7 +55,7 @@
#ifndef lint
static const char sccsid[] = "@(#)getinfo.c 5.26 (Berkeley) 3/21/91";
-static const char rcsid[] = "Id: getinfo.c,v 8.18 2001/02/27 06:03:40 vixie Exp";
+static const char rcsid[] = "Id: getinfo.c,v 8.27 2002/05/22 04:06:57 marka Exp";
#endif /* not lint */
/*
@@ -81,18 +81,19 @@
#include <arpa/inet.h>
#include <ctype.h>
-#include <resolv.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "port_after.h"
+#include <resolv.h>
+
#include "res.h"
-extern char *res_skip();
-
static char *addr_list[MAXADDRS + 1];
+static int addr_len[MAXADDRS + 1];
+static int addr_type[MAXADDRS + 1];
static char *host_aliases[MAXALIASES];
static int host_aliases_len[MAXALIASES];
@@ -103,6 +104,8 @@
char *domain[MAXDOMAINS];
int numDomains;
char *address[MAXADDRS];
+ char len[MAXADDRS];
+ char type[MAXADDRS];
int numAddresses;
} ServerTable;
@@ -140,41 +143,45 @@
*/
static int
-GetAnswer(nsAddrPtr, queryType, msg, msglen, iquery, hostPtr, isServer)
- struct in_addr *nsAddrPtr;
- char *msg;
- int queryType;
- int msglen;
- Boolean iquery;
- register HostInfo *hostPtr;
- Boolean isServer;
+GetAnswer(union res_sockaddr_union *nsAddrPtr, int queryType,
+ char *msg, int msglen, Boolean iquery, HostInfo *hostPtr,
+ Boolean isServer, Boolean merge)
{
register HEADER *headerPtr;
- register u_char *cp;
+ register const u_char *cp;
querybuf answer;
char **aliasPtr;
u_char *eom, *bp;
char **addrPtr;
+ int *lenPtr;
+ int *typePtr;
char *namePtr;
char *dnamePtr;
int type, class;
int qdcount, ancount, arcount, nscount, buflen;
- int origClass;
+ int origClass = 0;
int numAliases = 0;
int numAddresses = 0;
- int n, i, j;
+ int n, i, j, k, l, m;
int dlen;
int status;
int numServers;
size_t s;
Boolean haveAnswer;
Boolean printedAnswers = FALSE;
+ int oldAliases;
+ char **newAliases;
+ int oldServers;
+ ServerInfo **newServers;
+ int oldAddresses;
+ AddrInfo **newAddresses;
/*
* If the hostPtr was used before, free up the calloc'd areas.
*/
- FreeHostInfoPtr(hostPtr);
+ if (!merge)
+ FreeHostInfoPtr(hostPtr);
status = SendRequest(nsAddrPtr, (u_char *)msg, msglen, (u_char *) &answer,
sizeof(answer), &n);
@@ -222,6 +229,8 @@
aliasPtr = host_aliases;
addrPtr = addr_list;
+ lenPtr = addr_len;
+ typePtr = addr_type;
haveAnswer = FALSE;
/*
@@ -238,10 +247,11 @@
printf("Non-authoritative answer:\n");
}
- if (queryType != T_A && !(iquery && queryType == T_PTR)) {
+ if (queryType != T_A && queryType != T_AAAA && /* A6? */
+ !(iquery && queryType == T_PTR)) {
while (--ancount >= 0 && cp < eom) {
- if ((cp = (u_char *)Print_rr(cp,
- (u_char *)&answer, eom, stdout)) == NULL) {
+ if ((cp = Print_rr(cp, (u_char *)&answer,
+ eom, stdout)) == NULL) {
return(ERROR);
}
}
@@ -290,36 +300,34 @@
memcpy(hostPtr->name, bp, s);
haveAnswer = TRUE;
break;
- } else if (type != T_A) {
+ } else if (type != T_A && type != T_AAAA) {
cp += dlen;
continue;
}
- if (dlen != INADDRSZ)
+ if (type == T_A && dlen != INADDRSZ)
+ return (ERROR);
+ if (type == T_AAAA && dlen != 16)
return (ERROR);
if (haveAnswer) {
/*
* If we've already got 1 address, we aren't interested
- * in addresses with a different length or class.
+ * in addresses with a different class.
*/
- if (dlen != hostPtr->addrLen) {
- cp += dlen;
- continue;
- }
if (class != origClass) {
cp += dlen;
continue;
}
} else {
/*
- * First address: record its length and class so we
- * only save additonal ones with the same attributes.
+ * First address: record its class so we only save
+ * additonal ones with the same attributes.
*/
- hostPtr->addrLen = dlen;
origClass = class;
- hostPtr->addrType = (class == C_IN) ? AF_INET : AF_UNSPEC;
- s = strlen((char *)bp) + 1;
- hostPtr->name = Calloc(1, s);
- memcpy(hostPtr->name, bp, s);
+ if (hostPtr->name == NULL) {
+ s = strlen((char *)bp) + 1;
+ hostPtr->name = Calloc(1, s);
+ memcpy(hostPtr->name, bp, s);
+ }
}
bp += (((size_t)bp) % sizeof(align));
@@ -335,6 +343,10 @@
continue;
}
memcpy(*addrPtr++ = (char *)bp, cp, dlen);
+ *lenPtr++ = dlen;
+ *typePtr++ = (class == C_IN) ?
+ ((type == T_A) ? AF_INET : AF_INET6) :
+ AF_UNSPEC;
bp += dlen;
cp += dlen;
numAddresses++;
@@ -343,31 +355,74 @@
}
}
- if ((queryType == T_A || queryType == T_PTR) && haveAnswer) {
+ if ((queryType == T_A || queryType == T_AAAA || queryType == T_PTR) &&
+ haveAnswer) {
/*
* Go through the alias and address lists and return them
* in the hostPtr variable.
*/
+ oldAliases = 0;
+ if (merge && hostPtr->aliases != NULL) {
+ while (hostPtr->aliases[oldAliases] != NULL)
+ oldAliases++;
+ }
if (numAliases > 0) {
- hostPtr->aliases =
- (char **) Calloc(1 + numAliases, sizeof(char *));
+ newAliases =
+ (char **) Calloc(1 + numAliases + oldAliases, sizeof(char *));
+ if (merge && hostPtr->aliases != NULL) {
+ memcpy(newAliases, hostPtr->aliases,
+ oldAliases * sizeof(char *));
+ free(hostPtr->aliases);
+ }
+ hostPtr->aliases = newAliases;
+ k = oldAliases;
for (i = 0; i < numAliases; i++) {
- hostPtr->aliases[i] = Calloc(1, host_aliases_len[i]);
- memcpy(hostPtr->aliases[i], host_aliases[i],
+ for (l = 0; l < k; l++)
+ if (!strcasecmp(hostPtr->aliases[l], host_aliases[i]))
+ break;
+ if (l < k)
+ continue;
+ hostPtr->aliases[k] = Calloc(1, host_aliases_len[i]);
+ memcpy(hostPtr->aliases[k], host_aliases[i],
host_aliases_len[i]);
+ k++;
}
- hostPtr->aliases[i] = NULL;
+ hostPtr->aliases[k] = NULL;
+ }
+ oldAddresses = 0;
+ if (merge && hostPtr->addrList != NULL) {
+ while (hostPtr->addrList[oldAddresses] != NULL)
+ oldAddresses++;
}
if (numAddresses > 0) {
- hostPtr->addrList =
- (char **)Calloc(1+numAddresses, sizeof(char *));
+ newAddresses =
+ (AddrInfo **)Calloc(1+numAddresses, sizeof(AddrInfo *));
+ if (merge && hostPtr->addrList != NULL) {
+ memcpy(newAddresses, hostPtr->addrList,
+ oldAddresses * sizeof(char *));
+ free(hostPtr->addrList);
+ }
+ hostPtr->addrList = newAddresses;
+ k = oldAddresses;
for (i = 0; i < numAddresses; i++) {
- hostPtr->addrList[i] = Calloc(1, hostPtr->addrLen);
- memcpy(hostPtr->addrList[i], addr_list[i], hostPtr->addrLen);
+ for (l = 0; l < k; l++)
+ if (hostPtr->addrList[l]->addrType == addr_type[i] &&
+ hostPtr->addrList[l]->addrLen == addr_len[i] &&
+ !memcmp(hostPtr->addrList[l]->addr, addr_list[i],
+ addr_len[i]))
+ break;
+ if (l < k)
+ continue;
+ hostPtr->addrList[k] = (AddrInfo*)Calloc(1, sizeof(AddrInfo));
+ hostPtr->addrList[k]->addr = Calloc(1, addr_len[i]);
+ hostPtr->addrList[k]->addrType = addr_type[i];
+ hostPtr->addrList[k]->addrLen = addr_len[i];
+ memcpy(hostPtr->addrList[k]->addr, addr_list[i], addr_len[i]);
+ k++;
}
- hostPtr->addrList[i] = NULL;
+ hostPtr->addrList[k] = NULL;
}
#ifdef verbose
if (headerPtr->aa || nscount == 0) {
@@ -386,23 +441,24 @@
* in the additional resource records part.
*/
- if (!headerPtr->aa && (queryType != T_A) && (nscount > 0 || arcount > 0)) {
+ if (!headerPtr->aa && (queryType != T_A) && (queryType != T_AAAA) &&
+ (nscount > 0 || arcount > 0)) {
if (printedAnswers) {
putchar('\n');
}
printf("Authoritative answers can be found from:\n");
}
- cp = (u_char *)res_skip((char *) &answer, 2, eom);
+ cp = res_skip((u_char *)&answer, 2, eom);
numServers = 0;
- if (queryType != T_A) {
+ if (queryType != T_A && queryType != T_AAAA) {
/*
* If we don't need to save the record, just print it.
*/
Home |
Main Index |
Thread Index |
Old Index