summaryrefslogtreecommitdiff
path: root/usr.bin/netstat
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1998-06-23 22:40:56 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1998-06-23 22:40:56 +0000
commit30cb72a00b8cc59895c391cad0f8e31611611ec4 (patch)
tree3e2f67dd80af3489363cf0596b740c6533994e40 /usr.bin/netstat
parent325437057bbda9490b174c8fc6dc8f0e14a8f145 (diff)
Fix snprintf return value usage.
Diffstat (limited to 'usr.bin/netstat')
-rw-r--r--usr.bin/netstat/atalk.c17
-rw-r--r--usr.bin/netstat/route.c28
2 files changed, 34 insertions, 11 deletions
diff --git a/usr.bin/netstat/atalk.c b/usr.bin/netstat/atalk.c
index f6b33c45fb1..d57aa91b3bf 100644
--- a/usr.bin/netstat/atalk.c
+++ b/usr.bin/netstat/atalk.c
@@ -219,7 +219,7 @@ atalk_print2(sa, mask, what)
const struct sockaddr *mask;
int what;
{
- int n;
+ size_t n, l;
static char buf[100];
struct sockaddr_at *sat1, *sat2;
struct sockaddr_at thesockaddr;
@@ -232,15 +232,24 @@ atalk_print2(sa, mask, what)
thesockaddr.sat_addr.s_net = sat1->sat_addr.s_net &
sat2->sat_addr.s_net;
n = snprintf(buf, sizeof(buf), "%s", atalk_print(sa2, 1 | (what & 8)));
+ if (n >= sizeof(buf))
+ n = sizeof(buf) - 1;
if (sat2->sat_addr.s_net != 0xFFFF) {
thesockaddr.sat_addr.s_net = sat1->sat_addr.s_net |
~sat2->sat_addr.s_net;
- n += snprintf(buf + n, sizeof(buf) - n,
+ l = snprintf(buf + n, sizeof(buf) - n,
"-%s", atalk_print(sa2, 1 | (what & 8)));
+ if (l >= sizeof(buf) - n)
+ l = sizeof(buf) - n - 1;
+ n += l;
}
- if (what & 2)
- n += snprintf(buf + n, sizeof(buf) - n, ".%s",
+ if (what & 2) {
+ l = snprintf(buf + n, sizeof(buf) - n, ".%s",
atalk_print(sa, what & (~1)));
+ if (l >= sizeof(buf) - n)
+ l = sizeof(buf) - n - 1;
+ n += l;
+ }
return (buf);
}
diff --git a/usr.bin/netstat/route.c b/usr.bin/netstat/route.c
index 950e9d4c111..ced59780a73 100644
--- a/usr.bin/netstat/route.c
+++ b/usr.bin/netstat/route.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: route.c,v 1.24 1998/05/18 19:03:29 deraadt Exp $ */
+/* $OpenBSD: route.c,v 1.25 1998/06/23 22:40:40 millert 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.24 1998/05/18 19:03:29 deraadt Exp $";
+static char *rcsid = "$OpenBSD: route.c,v 1.25 1998/06/23 22:40:40 millert Exp $";
#endif
#endif /* not lint */
@@ -404,6 +404,7 @@ p_sockaddr(sa, mask, flags, width)
{
char workbuf[128], *cplim;
register char *cp = workbuf;
+ size_t n;
switch(sa->sa_family) {
case AF_INET:
@@ -444,9 +445,12 @@ p_sockaddr(sa, mask, flags, width)
cplim = "";
for (i = 0; i < sdl->sdl_alen; i++, lla++) {
- cp += snprintf(cp,
+ n = snprintf(cp,
workbuf + sizeof (workbuf) - cp,
"%s%x", cplim, *lla);
+ if (n >= workbuf + sizeof (workbuf) - cp)
+ n = workbuf + sizeof (workbuf) - cp - 1;
+ cp += n;
cplim = ":";
}
cp = workbuf;
@@ -471,14 +475,24 @@ p_sockaddr(sa, mask, flags, width)
slim = sa->sa_len + (u_char *) sa;
cplim = cp + sizeof(workbuf) - 6;
- cp += snprintf(cp, cplim - cp, "(%d)", sa->sa_family);
+ n = snprintf(cp, cplim - cp, "(%d)", sa->sa_family);
+ if (n >= cplim - cp)
+ n = cplim - cp - 1;
+ cp += n;
while (s < slim && cp < cplim) {
- cp += snprintf(cp, workbuf + sizeof (workbuf) - cp,
+ n = snprintf(cp, workbuf + sizeof (workbuf) - cp,
" %02x", *s++);
- if (s < slim)
- cp += snprintf(cp,
+ if (n >= workbuf + sizeof (workbuf) - cp)
+ n = workbuf + sizeof (workbuf) - cp - 1;
+ cp += n;
+ if (s < slim) {
+ n = snprintf(cp,
workbuf + sizeof (workbuf) - cp,
"%02x", *s++);
+ if (n >= workbuf + sizeof (workbuf) - cp)
+ n = workbuf + sizeof (workbuf) - cp - 1;
+ cp += n;
+ }
}
cp = workbuf;
}