summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1998-02-27 12:07:41 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1998-02-27 12:07:41 +0000
commit9407cfed1cac496d0a5a10617268bb2984daee89 (patch)
treee7b7e64079e6cd90e5b7f6628d5efb7a573b6133 /usr.bin
parentd2f889cf2db294503934d45c7d9743ae5ee539df (diff)
oflow paranoia
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/netstat/if.c14
-rw-r--r--usr.bin/netstat/inet.c29
-rw-r--r--usr.bin/netstat/ipx.c7
-rw-r--r--usr.bin/netstat/iso.c15
-rw-r--r--usr.bin/netstat/mroute.c4
-rw-r--r--usr.bin/netstat/ns.c7
-rw-r--r--usr.bin/netstat/route.c51
7 files changed, 71 insertions, 56 deletions
diff --git a/usr.bin/netstat/if.c b/usr.bin/netstat/if.c
index 256fd261ed7..acea93bbf6d 100644
--- a/usr.bin/netstat/if.c
+++ b/usr.bin/netstat/if.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if.c,v 1.16 1997/07/25 04:28:59 mickey Exp $ */
+/* $OpenBSD: if.c,v 1.17 1998/02/27 12:07:32 deraadt Exp $ */
/* $NetBSD: if.c,v 1.16.4.2 1996/06/07 21:46:46 thorpej Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "from: @(#)if.c 8.2 (Berkeley) 2/21/94";
#else
-static char *rcsid = "$OpenBSD: if.c,v 1.16 1997/07/25 04:28:59 mickey Exp $";
+static char *rcsid = "$OpenBSD: if.c,v 1.17 1998/02/27 12:07:32 deraadt Exp $";
#endif
#endif /* not lint */
@@ -200,8 +200,9 @@ intpr(interval, ifnetaddr)
u_long net;
char netnum[8];
- *(union ipx_net *) &net = sipx->sipx_addr.ipx_net;
- sprintf(netnum, "%xH", ntohl(net));
+ *(union ipx_net *)&net = sipx->sipx_addr.ipx_net;
+ snprintf(netnum, sizeof netnum, "%xH",
+ ntohl(net));
upHex(netnum);
printf("ipx:%-8s", netnum);
printf("%-17s ",
@@ -219,8 +220,9 @@ intpr(interval, ifnetaddr)
u_long net;
char netnum[8];
- *(union ns_net *) &net = sns->sns_addr.x_net;
- sprintf(netnum, "%xH", ntohl(net));
+ *(union ns_net *)&net = sns->sns_addr.x_net;
+ snprintf(netnum, sizeof netnum, "%xH",
+ ntohl(net));
upHex(netnum);
printf("ns:%-8s ", netnum);
printf("%-17s ",
diff --git a/usr.bin/netstat/inet.c b/usr.bin/netstat/inet.c
index a66672f4359..080371755d1 100644
--- a/usr.bin/netstat/inet.c
+++ b/usr.bin/netstat/inet.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: inet.c,v 1.22 1997/11/09 16:33:09 provos Exp $ */
+/* $OpenBSD: inet.c,v 1.23 1998/02/27 12:07:33 deraadt Exp $ */
/* $NetBSD: inet.c,v 1.14 1995/10/03 21:42:37 thorpej Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "from: @(#)inet.c 8.4 (Berkeley) 4/20/94";
#else
-static char *rcsid = "$OpenBSD: inet.c,v 1.22 1997/11/09 16:33:09 provos Exp $";
+static char *rcsid = "$OpenBSD: inet.c,v 1.23 1998/02/27 12:07:33 deraadt Exp $";
#endif
#endif /* not lint */
@@ -454,7 +454,7 @@ getrpcportnam(port, proto)
static int first;
static struct rpcnams *rpcn;
struct rpcnams *n;
- char num[10];
+ char num[20];
if (first == 0) {
first = 1;
@@ -490,7 +490,8 @@ getrpcportnam(port, proto)
if (rpc)
n->rpcname = strdup(rpc->r_name);
else {
- sprintf(num, "%ld", head->pml_map.pm_prog);
+ snprintf(num, sizeof num, "%ld",
+ head->pml_map.pm_prog);
n->rpcname = strdup(num);
}
}
@@ -519,17 +520,20 @@ inetprint(in, port, proto, local)
int proton;
int width;
- sprintf(line, "%.*s.", (Aflag && !nflag) ? 12 : 16, inetname(in));
+ snprintf(line, sizeof line, "%.*s.", (Aflag && !nflag) ? 12 : 16,
+ inetname(in));
cp = strchr(line, '\0');
if (!nflag && port)
sp = getservbyport((int)port, proto);
if (sp || port == 0)
- sprintf(cp, "%.8s", sp ? sp->s_name : "*");
+ snprintf(cp, line + sizeof line - cp, "%.8s",
+ sp ? sp->s_name : "*");
else if (local && !nflag && (nam = getrpcportnam(ntohs(port),
(strcmp(proto, "tcp") == 0 ? IPPROTO_TCP : IPPROTO_UDP))))
- sprintf(cp, "%d[%.8s]", ntohs(port), nam);
+ snprintf(cp, line + sizeof line - cp, "%d[%.8s]",
+ ntohs(port), nam);
else
- sprintf(cp, "%d", ntohs(port));
+ snprintf(cp, line + sizeof line - cp, "%d", ntohs(port));
width = Aflag ? 18 : 22;
printf(" %-*.*s", width, width, line);
}
@@ -579,14 +583,15 @@ inetname(inp)
}
}
if (inp->s_addr == INADDR_ANY)
- strcpy(line, "*");
+ snprintf(line, sizeof line, "*");
else if (cp)
- strcpy(line, cp);
+ snprintf(line, sizeof line, "%s", cp);
else {
inp->s_addr = ntohl(inp->s_addr);
#define C(x) ((x) & 0xff)
- sprintf(line, "%u.%u.%u.%u", C(inp->s_addr >> 24),
- C(inp->s_addr >> 16), C(inp->s_addr >> 8), C(inp->s_addr));
+ snprintf(line, sizeof line, "%u.%u.%u.%u",
+ C(inp->s_addr >> 24), C(inp->s_addr >> 16),
+ C(inp->s_addr >> 8), C(inp->s_addr));
}
return (line);
}
diff --git a/usr.bin/netstat/ipx.c b/usr.bin/netstat/ipx.c
index cd36cee4b55..d91a773e0d2 100644
--- a/usr.bin/netstat/ipx.c
+++ b/usr.bin/netstat/ipx.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ipx.c,v 1.4 1997/06/29 21:46:01 millert Exp $ */
+/* $OpenBSD: ipx.c,v 1.5 1998/02/27 12:07:34 deraadt Exp $ */
/*
* Copyright (c) 1996 Michael Shalayeff
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "from: @(#)ns.c 8.1 (Berkeley) 6/6/93";
#else
-static char *rcsid = "$OpenBSD: ipx.c,v 1.4 1997/06/29 21:46:01 millert Exp $";
+static char *rcsid = "$OpenBSD: ipx.c,v 1.5 1998/02/27 12:07:34 deraadt Exp $";
#endif
#endif /* not lint */
@@ -337,7 +337,8 @@ ipx_erputil(z, c)
where = "in transit";
else
where = "at destination";
- sprintf(codebuf, "Unknown IPX error code 0%o", c);
+ snprintf(codebuf, sizeof codebuf,
+ "Unknown IPX error code 0%o", c);
name = codebuf;
} else
where = ipx_errnames[j].where;
diff --git a/usr.bin/netstat/iso.c b/usr.bin/netstat/iso.c
index 70794634d87..e1079c72e9d 100644
--- a/usr.bin/netstat/iso.c
+++ b/usr.bin/netstat/iso.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: iso.c,v 1.6 1997/06/29 21:46:02 millert Exp $ */
+/* $OpenBSD: iso.c,v 1.7 1998/02/27 12:07:36 deraadt Exp $ */
/* $NetBSD: iso.c,v 1.12 1995/10/03 21:42:38 thorpej Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "from: @(#)iso.c 8.1 (Berkeley) 6/6/93";
#else
-static char *rcsid = "$OpenBSD: iso.c,v 1.6 1997/06/29 21:46:02 millert Exp $";
+static char *rcsid = "$OpenBSD: iso.c,v 1.7 1998/02/27 12:07:36 deraadt Exp $";
#endif
#endif /* not lint */
@@ -401,12 +401,12 @@ isonetname(iso)
if( ihe ) {
Ihe = *ihe;
ihe = &Ihe;
- sprintf(line, "%s", ihe->isoh_hname);
+ snprintf(line, sizeof line, "%s", ihe->isoh_hname);
} else {
- sprintf(line, "%s", iso_ntoa(iso));
+ snprintf(line, sizeof line, "%s", iso_ntoa(iso));
}
} else {
- sprintf(line, "*");
+ snprintf(line, sizeof line, "*");
}
return line;
}
@@ -449,12 +449,13 @@ isonetprint(iso, sufx, sufxlen, islocal)
ihe = &Ihe;
}
if( ihe && (strlen(ihe->isoh_aname)>0) ) {
- sprintf(cp, "%s", ihe->isoh_aname);
+ snprintf(cp, line + sizeof line - cp, "%s",
+ ihe->isoh_aname);
} else {
iso_sprinttsel(cp, sufx, sufxlen);
}
} else
- sprintf(cp, "*");
+ snprintf(cp, line + sizeof line - cp, "*");
/*
fprintf(stdout, Aflag?" %-18.18s":" %-22.22s", line);
*/
diff --git a/usr.bin/netstat/mroute.c b/usr.bin/netstat/mroute.c
index 2aac6025700..1f1775be966 100644
--- a/usr.bin/netstat/mroute.c
+++ b/usr.bin/netstat/mroute.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mroute.c,v 1.5 1997/06/29 21:46:03 millert Exp $ */
+/* $OpenBSD: mroute.c,v 1.6 1998/02/27 12:07:37 deraadt Exp $ */
/* $NetBSD: mroute.c,v 1.10 1996/05/11 13:51:27 mycroft Exp $ */
/*
@@ -81,7 +81,7 @@ pktscale(n)
n /= 1048576;
}
- sprintf(buf, "%lu%c", n, t);
+ snprintf(buf, sizeof buf, "%lu%c", n, t);
return (buf);
}
diff --git a/usr.bin/netstat/ns.c b/usr.bin/netstat/ns.c
index 0da7a684a81..37cec756816 100644
--- a/usr.bin/netstat/ns.c
+++ b/usr.bin/netstat/ns.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ns.c,v 1.4 1997/06/29 21:46:05 millert Exp $ */
+/* $OpenBSD: ns.c,v 1.5 1998/02/27 12:07:38 deraadt Exp $ */
/* $NetBSD: ns.c,v 1.8 1995/10/03 21:42:46 thorpej Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "from: @(#)ns.c 8.1 (Berkeley) 6/6/93";
#else
-static char *rcsid = "$OpenBSD: ns.c,v 1.4 1997/06/29 21:46:05 millert Exp $";
+static char *rcsid = "$OpenBSD: ns.c,v 1.5 1998/02/27 12:07:38 deraadt Exp $";
#endif
#endif /* not lint */
@@ -344,7 +344,8 @@ ns_erputil(z, c)
where = "in transit";
else
where = "at destination";
- sprintf(codebuf, "Unknown XNS error code 0%o", c);
+ snprintf(codebuf, sizeof codebuf,
+ "Unknown XNS error code 0%o", c);
name = codebuf;
} else
where = ns_errnames[j].where;
diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c
index ede80196681..3d2132cd69f 100644
--- a/usr.bin/netstat/route.c
+++ b/usr.bin/netstat/route.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: route.c,v 1.22 1998/02/26 10:13:08 deraadt Exp $ */
+/* $OpenBSD: route.c,v 1.23 1998/02/27 12:07:40 deraadt Exp $ */
/* $NetBSD: route.c,v 1.15 1996/05/07 02:55:06 thorpej Exp $ */
/*
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "from: @(#)route.c 8.3 (Berkeley) 3/9/94";
#else
-static char *rcsid = "$OpenBSD: route.c,v 1.22 1998/02/26 10:13:08 deraadt Exp $";
+static char *rcsid = "$OpenBSD: route.c,v 1.23 1998/02/27 12:07:40 deraadt Exp $";
#endif
#endif /* not lint */
@@ -290,7 +290,7 @@ again:
}
}
-char nbuf[20];
+char nbuf[25];
static void
p_rtnode()
@@ -305,13 +305,13 @@ p_rtnode()
} else if (rm == 0)
return;
} else {
- sprintf(nbuf, "(%d)", rnode.rn_b);
+ snprintf(nbuf, sizeof nbuf, "(%d)", rnode.rn_b);
printf("%6.6s %16p : %16p", nbuf, rnode.rn_l,
rnode.rn_r);
}
while (rm) {
kget(rm, rmask);
- sprintf(nbuf, " %d refs, ", rmask.rm_refs);
+ snprintf(nbuf, sizeof nbuf, " %d refs, ", rmask.rm_refs);
printf(" mk = %16p {(%d),%s",
rm, -1 - rmask.rm_b, rmask.rm_refs ? nbuf : " ");
p_sockaddr(kgetsa((struct sockaddr *)rmask.rm_mask), 0, 0, -1);
@@ -433,7 +433,8 @@ p_sockaddr(sa, mask, flags, width)
if (sdl->sdl_nlen == 0 && sdl->sdl_alen == 0 &&
sdl->sdl_slen == 0)
- (void) sprintf(workbuf, "link#%d", sdl->sdl_index);
+ (void) snprintf(workbuf, sizeof workbuf,
+ "link#%d", sdl->sdl_index);
else switch (sdl->sdl_type) {
case IFT_ETHER:
{
@@ -470,7 +471,7 @@ p_sockaddr(sa, mask, flags, width)
slim = sa->sa_len + (u_char *) sa;
cplim = cp + sizeof(workbuf) - 6;
- cp += sprintf(cp, "(%d)", sa->sa_family);
+ cp += snprintf(cp, cplim - cp, "(%d)", sa->sa_family);
while (s < slim && cp < cplim) {
cp += snprintf(cp, workbuf + sizeof (workbuf) - cp,
" %02x", *s++);
@@ -581,7 +582,7 @@ routename(in)
} else {
#define C(x) ((x) & 0xff)
in = ntohl(in);
- sprintf(line, "%u.%u.%u.%u",
+ snprintf(line, sizeof line, "%u.%u.%u.%u",
C(in >> 24), C(in >> 16), C(in >> 8), C(in));
}
return (line);
@@ -612,13 +613,15 @@ netname(in, mask)
strncpy(line, cp, sizeof(line) - 1);
line[sizeof(line) - 1] = '\0';
} else if ((in & 0xffffff) == 0)
- sprintf(line, "%u/%d", C(in >> 24), mbits);
+ snprintf(line, sizeof line, "%u/%d", C(in >> 24), mbits);
else if ((in & 0xffff) == 0)
- sprintf(line, "%u.%u/%d", C(in >> 24) , C(in >> 16), mbits);
+ snprintf(line, sizeof line, "%u.%u/%d",
+ C(in >> 24) , C(in >> 16), mbits);
else if ((in & 0xff) == 0)
- sprintf(line, "%u.%u.%u/%d", C(in >> 24), C(in >> 16), C(in >> 8), mbits);
+ snprintf(line, sizeof line, "%u.%u.%u/%d",
+ C(in >> 24), C(in >> 16), C(in >> 8), mbits);
else
- sprintf(line, "%u.%u.%u.%u/%d", C(in >> 24),
+ snprintf(line, sizeof line, "%u.%u.%u.%u/%d", C(in >> 24),
C(in >> 16), C(in >> 8), C(in), mbits);
return (line);
}
@@ -671,10 +674,10 @@ ns_print(sa)
net.net_e = work.x_net;
if (ns_nullhost(work) && net.long_e == 0) {
if (port ) {
- sprintf(mybuf, "*.%xH", port);
+ snprintf(mybuf, sizeof mybuf, "*.%xH", port);
upHex(mybuf);
} else
- sprintf(mybuf, "*.*");
+ snprintf(mybuf, sizeof mybuf, "*.*");
return (mybuf);
}
@@ -684,18 +687,19 @@ ns_print(sa)
host = "*";
} else {
q = work.x_host.c_host;
- sprintf(chost, "%02x%02x%02x%02x%02x%02xH",
+ snprintf(chost, sizeof chost, "%02x%02x%02x%02x%02x%02xH",
q[0], q[1], q[2], q[3], q[4], q[5]);
for (p = chost; *p == '0' && p < chost + 12; p++)
continue;
host = p;
}
if (port)
- sprintf(cport, ".%xH", htons(port));
+ snprintf(cport, sizeof cport, ".%xH", htons(port));
else
*cport = 0;
- sprintf(mybuf,"%xH.%s%s", ntohl(net.long_e), host, cport);
+ snprintf(mybuf, sizeof mybuf, "%xH.%s%s", ntohl(net.long_e),
+ host, cport);
upHex(mybuf);
return(mybuf);
}
@@ -739,10 +743,10 @@ ipx_print(sa)
net.net_e = work.ipx_net;
if (ipx_nullhost(work) && net.long_e == 0) {
if (port != 0) {
- sprintf(mybuf, "*.%xH", port);
+ snprintf(mybuf, sizeof mybuf, "*.%xH", port);
upHex(mybuf);
} else
- sprintf(mybuf, "*.*");
+ snprintf(mybuf, sizeof mybuf, "*.*");
return (mybuf);
}
@@ -752,16 +756,17 @@ ipx_print(sa)
host = "*";
} else {
q = work.ipx_host.c_host;
- sprintf(chost, "%02x:%02x:%02x:%02x:%02x:%02x",
- q[0], q[1], q[2], q[3], q[4], q[5]);
+ snprintf(chost, sizeof chost, "%02x:%02x:%02x:%02x:%02x:%02x",
+ q[0], q[1], q[2], q[3], q[4], q[5]);
host = chost;
}
if (port)
- sprintf(cport, ".%xH", htons(port));
+ snprintf(cport, sizeof cport, ".%xH", htons(port));
else
*cport = 0;
- sprintf(mybuf,"%xH.%s%s", ntohl(net.long_e), host, cport);
+ snprintf(mybuf, sizeof mybuf, "%xH.%s%s", ntohl(net.long_e),
+ host, cport);
upHex(mybuf);
return(mybuf);
}