summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1998-07-13 22:13:48 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1998-07-13 22:13:48 +0000
commit63405a5a2780376bf4481817444eba3d65ede79b (patch)
tree4648668dfc4e764f2be03fd266242958ad08e387
parentc31cfbe096652f4f20172428918913e49806b059 (diff)
snprintf madness
-rw-r--r--usr.sbin/tcpdump/print-atalk.c11
-rw-r--r--usr.sbin/tcpdump/print-icmp.c52
2 files changed, 35 insertions, 28 deletions
diff --git a/usr.sbin/tcpdump/print-atalk.c b/usr.sbin/tcpdump/print-atalk.c
index c6626571fbb..9b3731d5c3d 100644
--- a/usr.sbin/tcpdump/print-atalk.c
+++ b/usr.sbin/tcpdump/print-atalk.c
@@ -23,7 +23,7 @@
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-atalk.c,v 1.8 1998/05/14 21:16:51 deraadt Exp $ (LBL)";
+ "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-atalk.c,v 1.9 1998/07/13 22:13:46 deraadt Exp $ (LBL)";
#endif
#include <sys/param.h>
@@ -587,7 +587,8 @@ ataddr_string(u_short atnet, u_char athost)
if (tp2->addr == i) {
tp->addr = (atnet << 8) | athost;
tp->nxt = newhnamemem();
- (void)sprintf(nambuf, "%s.%d", tp2->name, athost);
+ (void)snprintf(nambuf, sizeof nambuf, "%s.%d",
+ tp2->name, athost);
tp->name = savestr(nambuf);
return (tp->name);
}
@@ -595,9 +596,9 @@ ataddr_string(u_short atnet, u_char athost)
tp->addr = (atnet << 8) | athost;
tp->nxt = newhnamemem();
if (athost != 255)
- (void)sprintf(nambuf, "%d.%d", atnet, athost);
+ (void)snprintf(nambuf, sizeof nambuf, "%d.%d", atnet, athost);
else
- (void)sprintf(nambuf, "%d", atnet);
+ (void)snprintf(nambuf, sizeof nambuf, "%d", atnet);
tp->name = savestr(nambuf);
return (tp->name);
@@ -614,7 +615,7 @@ static struct tok skt2str[] = {
static const char *
ddpskt_string(register int skt)
{
- static char buf[8];
+ static char buf[10];
if (nflag) {
(void)sprintf(buf, "%d", skt);
diff --git a/usr.sbin/tcpdump/print-icmp.c b/usr.sbin/tcpdump/print-icmp.c
index f03c893b0a1..84a9c63a2a5 100644
--- a/usr.sbin/tcpdump/print-icmp.c
+++ b/usr.sbin/tcpdump/print-icmp.c
@@ -21,7 +21,7 @@
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-icmp.c,v 1.6 1997/07/25 20:12:24 mickey Exp $ (LBL)";
+ "@(#) $Header: /cvs/OpenBSD/src/usr.sbin/tcpdump/print-icmp.c,v 1.7 1998/07/13 22:13:47 deraadt Exp $ (LBL)";
#endif
#include <sys/param.h>
@@ -172,7 +172,7 @@ icmp_print(register const u_char *bp, register const u_char *bp2)
register const struct ip *oip;
register const struct udphdr *ouh;
register u_int hlen, dport, mtu;
- char buf[256];
+ char buf[MAXHOSTNAMELEN+256];
dp = (struct icmp *)bp;
ip = (struct ip *)bp2;
@@ -191,7 +191,8 @@ icmp_print(register const u_char *bp, register const u_char *bp2)
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;
@@ -205,21 +206,21 @@ icmp_print(register const u_char *bp, register const u_char *bp2)
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);
@@ -234,11 +235,11 @@ icmp_print(register const u_char *bp, register const u_char *bp2)
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));
}
@@ -247,7 +248,7 @@ icmp_print(register const u_char *bp, register const u_char *bp2)
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;
}
@@ -257,7 +258,7 @@ icmp_print(register const u_char *bp, register const u_char *bp2)
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;
@@ -268,7 +269,8 @@ icmp_print(register const u_char *bp, register const u_char *bp2)
register const struct id_rdiscovery *idp;
u_int lifetime, num, size;
- (void)strcpy(buf, "router advertisement");
+ (void)strncpy(buf, "router advertisement", sizeof buf-1);
+ buf[sizeof buf-1] = '\0';
cp = buf + strlen(buf);
ihp = (struct ih_rdiscovery *)&dp->icmp_void;
@@ -277,30 +279,31 @@ icmp_print(register const u_char *bp, register const u_char *bp2)
cp = buf + strlen(buf);
lifetime = EXTRACT_16BITS(&ihp->ird_lifetime);
if (lifetime < 60)
- (void)sprintf(cp, "%u", lifetime);
+ (void)snprintf(cp, buf + sizeof buf - cp, "%u", lifetime);
else if (lifetime < 60 * 60)
- (void)sprintf(cp, "%u:%02u",
+ (void)snprintf(cp, buf + sizeof buf - cp, "%u:%02u",
lifetime / 60, lifetime % 60);
else
- (void)sprintf(cp, "%u:%02u:%02u",
+ (void)snprintf(cp, buf + sizeof buf - cp, "%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, buf + sizeof buf - cp, " %d:", num);
cp = buf + strlen(buf);
size = ihp->ird_addrsiz;
if (size != 2) {
- (void)sprintf(cp, " [size %d]", size);
+ (void)snprintf(cp, buf - sizeof buf - cp,
+ " [size %d]", size);
break;
}
idp = (struct id_rdiscovery *)&dp->icmp_data;
while (num-- > 0) {
TCHECK(*idp);
- (void)sprintf(cp, " {%s %u}",
+ (void)snprintf(cp, buf + sizeof buf - cp, " {%s %u}",
ipaddr_string(&idp->ird_addr),
EXTRACT_32BITS(&idp->ird_pref));
cp = buf + strlen(buf);
@@ -321,25 +324,28 @@ icmp_print(register const u_char *bp, register const u_char *bp2)
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",
- dp->icmp_code);
+ (void)snprintf(buf, sizeof buf,
+ "parameter problem - code %d",
+ dp->icmp_code);
else {
TCHECK(dp->icmp_pptr);
- (void)sprintf(buf, "parameter problem - octet %d",
- dp->icmp_pptr);
+ (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;