Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-1-5]: src/usr.sbin/tcpdump Pullup 1.7 [he]:
details: https://anonhg.NetBSD.org/src/rev/8e20a01a1781
branches: netbsd-1-5
changeset: 490047:8e20a01a1781
user: tv <tv%NetBSD.org@localhost>
date: Wed Nov 01 02:46:58 2000 +0000
description:
Pullup 1.7 [he]:
Change from sprintf() to snprintf() where we may print externally
supplied data of unknown length.
Changes adapted from FreeBSD-SA-00:61.
diffstat:
usr.sbin/tcpdump/print-icmp.c | 52 ++++++++++++++++++++++++------------------
1 files changed, 30 insertions(+), 22 deletions(-)
diffs (169 lines):
diff -r fb2f5be8922c -r 8e20a01a1781 usr.sbin/tcpdump/print-icmp.c
--- a/usr.sbin/tcpdump/print-icmp.c Wed Nov 01 02:46:46 2000 +0000
+++ b/usr.sbin/tcpdump/print-icmp.c Wed Nov 01 02:46:58 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: print-icmp.c,v 1.6 1999/07/02 11:31:32 itojun Exp $ */
+/* $NetBSD: print-icmp.c,v 1.6.8.1 2000/11/01 02:46:58 tv Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1993, 1994, 1995, 1996
@@ -27,7 +27,7 @@
static const char rcsid[] =
"@(#) Header: print-icmp.c,v 1.38 96/09/26 23:36:44 leres Exp (LBL)";
#else
-__RCSID("$NetBSD: print-icmp.c,v 1.6 1999/07/02 11:31:32 itojun Exp $");
+__RCSID("$NetBSD: print-icmp.c,v 1.6.8.1 2000/11/01 02:46:58 tv Exp $");
#endif
#endif
@@ -183,7 +183,7 @@
register const struct ip *oip;
register const struct udphdr *ouh;
register u_int hlen, dport, mtu;
- char buf[256];
+ char buf[MAXHOSTNAMELEN + 100];
dp = (struct icmp *)bp;
ip = (struct ip *)bp2;
@@ -204,7 +204,8 @@
case ICMP_UNREACH_PROTOCOL:
TCHECK(dp->icmp_ip.ip_p);
- (void)sprintf(buf, "%s protocol %d unreachable",
+ (void)snprintf(buf, sizeof(buf),
+ "%s protocol %d unreachable",
ipaddr_string(&dp->icmp_ip.ip_dst),
dp->icmp_ip.ip_p);
break;
@@ -218,21 +219,21 @@
switch (oip->ip_p) {
case IPPROTO_TCP:
- (void)sprintf(buf,
+ (void)snprintf(buf, sizeof(buf),
"%s tcp port %s unreachable",
ipaddr_string(&oip->ip_dst),
tcpport_string(dport));
break;
case IPPROTO_UDP:
- (void)sprintf(buf,
+ (void)snprintf(buf, sizeof(buf),
"%s udp port %s unreachable",
ipaddr_string(&oip->ip_dst),
udpport_string(dport));
break;
default:
- (void)sprintf(buf,
+ (void)snprintf(buf, sizeof(buf),
"%s protocol %d port %d unreachable",
ipaddr_string(&oip->ip_dst),
oip->ip_p, dport);
@@ -247,11 +248,11 @@
mp = (struct mtu_discovery *)&dp->icmp_void;
mtu = EXTRACT_16BITS(&mp->nexthopmtu);
if (mtu)
- (void)sprintf(buf,
+ (void)snprintf(buf, sizeof(buf),
"%s unreachable - need to frag (mtu %d)",
ipaddr_string(&dp->icmp_ip.ip_dst), mtu);
else
- (void)sprintf(buf,
+ (void)snprintf(buf, sizeof(buf),
"%s unreachable - need to frag",
ipaddr_string(&dp->icmp_ip.ip_dst));
}
@@ -260,7 +261,7 @@
default:
fmt = tok2str(unreach2str, "#%d %%s unreachable",
dp->icmp_code);
- (void)sprintf(buf, fmt,
+ (void)snprintf(buf, sizeof(buf), fmt,
ipaddr_string(&dp->icmp_ip.ip_dst));
break;
}
@@ -270,7 +271,7 @@
TCHECK(dp->icmp_ip.ip_dst);
fmt = tok2str(type2str, "redirect-#%d %%s to net %%s",
dp->icmp_code);
- (void)sprintf(buf, fmt,
+ (void)snprintf(buf, sizeof(buf), fmt,
ipaddr_string(&dp->icmp_ip.ip_dst),
ipaddr_string(&dp->icmp_gwaddr));
break;
@@ -290,30 +291,34 @@
cp = buf + strlen(buf);
lifetime = EXTRACT_16BITS(&ihp->ird_lifetime);
if (lifetime < 60)
- (void)sprintf(cp, "%u", lifetime);
+ (void)snprintf(cp, sizeof(buf) - strlen(buf),
+ "%u", lifetime);
else if (lifetime < 60 * 60)
- (void)sprintf(cp, "%u:%02u",
- lifetime / 60, lifetime % 60);
+ (void)snprintf(cp, sizeof(buf) - strlen(buf),
+ "%u:%02u", lifetime / 60, lifetime % 60);
else
- (void)sprintf(cp, "%u:%02u:%02u",
+ (void)snprintf(cp, sizeof(buf) - strlen(buf),
+ "%u:%02u:%02u",
lifetime / 3600,
(lifetime % 3600) / 60,
lifetime % 60);
cp = buf + strlen(buf);
num = ihp->ird_addrnum;
- (void)sprintf(cp, " %d:", num);
+ (void)snprintf(cp, sizeof(buf) - strlen(buf), " %d:", num);
cp = buf + strlen(buf);
size = ihp->ird_addrsiz;
if (size != 2) {
- (void)sprintf(cp, " [size %d]", size);
+ (void)snprintf(cp, sizeof(buf) - strlen(buf),
+ " [size %d]", size);
break;
}
idp = (struct id_rdiscovery *)&dp->icmp_data;
while (num-- > 0) {
TCHECK(*idp);
- (void)sprintf(cp, " {%s %u}",
+ (void)snprintf(cp, sizeof(buf) - strlen(buf),
+ " {%s %u}",
ipaddr_string(&idp->ird_addr),
EXTRACT_32BITS(&idp->ird_pref));
cp = buf + strlen(buf);
@@ -334,25 +339,28 @@
break;
default:
- (void)sprintf(buf, "time exceeded-#%d", dp->icmp_code);
+ (void)snprintf(buf, sizeof(buf),
+ "time exceeded-#%d", dp->icmp_code);
break;
}
break;
case ICMP_PARAMPROB:
if (dp->icmp_code)
- (void)sprintf(buf, "parameter problem - code %d",
+ (void)snprintf(buf, sizeof(buf),
+ "parameter problem - code %d",
dp->icmp_code);
else {
TCHECK(dp->icmp_pptr);
- (void)sprintf(buf, "parameter problem - octet %d",
+ (void)snprintf(buf, sizeof(buf),
+ "parameter problem - octet %d",
dp->icmp_pptr);
}
break;
case ICMP_MASKREPLY:
TCHECK(dp->icmp_mask);
- (void)sprintf(buf, "address mask is 0x%08x",
+ (void)snprintf(buf, sizeof(buf), "address mask is 0x%08x",
(u_int32_t)ntohl(dp->icmp_mask));
break;
Home |
Main Index |
Thread Index |
Old Index