From 30cb72a00b8cc59895c391cad0f8e31611611ec4 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 23 Jun 1998 22:40:56 +0000 Subject: Fix snprintf return value usage. --- usr.bin/netstat/atalk.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'usr.bin/netstat/atalk.c') 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); } -- cgit v1.2.3