diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2003-04-21 02:06:53 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2003-04-21 02:06:53 +0000 |
commit | 7eac84185ec5f4542676bac47e488e5989bab63b (patch) | |
tree | 75fe43eb5de85ee7e67d24b60280537ca8f715b6 /sbin/routed | |
parent | b65cfbc7feae77983e6e126c14d209aadb9943bf (diff) |
a few string cleanups; ok dhartmei
Diffstat (limited to 'sbin/routed')
-rw-r--r-- | sbin/routed/table.c | 31 | ||||
-rw-r--r-- | sbin/routed/trace.c | 12 |
2 files changed, 27 insertions, 16 deletions
diff --git a/sbin/routed/table.c b/sbin/routed/table.c index 3c986543211..cd371b7b7d1 100644 --- a/sbin/routed/table.c +++ b/sbin/routed/table.c @@ -1,4 +1,4 @@ -/* $OpenBSD: table.c,v 1.11 2003/04/17 07:39:24 pvalchev Exp $ */ +/* $OpenBSD: table.c,v 1.12 2003/04/21 02:06:52 deraadt Exp $ */ /* * Copyright (c) 1983, 1988, 1993 @@ -1091,8 +1091,11 @@ read_rt(void) strlcpy(str, rtm_type_name(m.r.rtm.rtm_type), sizeof str); strp = &str[strlen(str)]; - if (m.r.rtm.rtm_type <= RTM_CHANGE) - strp += sprintf(strp," from pid %ld", (long)m.r.rtm.rtm_pid); + if (m.r.rtm.rtm_type <= RTM_CHANGE) { + snprintf(strp, str + sizeof str - strp, + " from pid %ld", (long)m.r.rtm.rtm_pid); + strp+= strlen(strp); + } rt_xaddrs(&info, m.r.addrs, &m.r.addrs[RTAX_MAX], m.r.rtm.rtm_addrs); @@ -1114,8 +1117,9 @@ read_rt(void) ? HOST_MASK : std_mask(S_ADDR(INFO_DST(&info)))); - strp += sprintf(strp, ": %s", - addrname(S_ADDR(INFO_DST(&info)), mask, 0)); + snprintf(strp, str + sizeof str - strp, ": %s", + addrname(S_ADDR(INFO_DST(&info)), mask, 0)); + strp+= strlen(strp); if (IN_MULTICAST(ntohl(S_ADDR(INFO_DST(&info))))) { trace_act("ignore multicast %s\n", str); @@ -1123,13 +1127,18 @@ read_rt(void) } if (INFO_GATE(&info) != 0 - && INFO_GATE(&info)->sa_family == AF_INET) - strp += sprintf(strp, " --> %s", - saddr_ntoa(INFO_GATE(&info))); + && INFO_GATE(&info)->sa_family == AF_INET) { + snprintf(strp, str + sizeof str - strp, + " --> %s", saddr_ntoa(INFO_GATE(&info))); + strp+= strlen(strp); + } - if (INFO_AUTHOR(&info) != 0) - strp += sprintf(strp, " by authority of %s", - saddr_ntoa(INFO_AUTHOR(&info))); + if (INFO_AUTHOR(&info) != 0) { + snprintf(strp, str + sizeof str - strp, + " by authority of %s", + saddr_ntoa(INFO_AUTHOR(&info))); + strp+= strlen(strp); + } switch (m.r.rtm.rtm_type) { case RTM_ADD: diff --git a/sbin/routed/trace.c b/sbin/routed/trace.c index 10d4cc5a810..b48cfee7982 100644 --- a/sbin/routed/trace.c +++ b/sbin/routed/trace.c @@ -1,4 +1,4 @@ -/* $OpenBSD: trace.c,v 1.10 2003/03/13 09:09:27 deraadt Exp $ */ +/* $OpenBSD: trace.c,v 1.11 2003/04/21 02:06:52 deraadt Exp $ */ /* $NetBSD: trace.c,v 1.13 1995/06/20 22:28:03 christos Exp $ */ /* @@ -37,7 +37,7 @@ #if !defined(lint) static char sccsid[] = "@(#)trace.c 8.1 (Berkeley) 6/5/93"; #else -static char rcsid[] = "$OpenBSD: trace.c,v 1.10 2003/03/13 09:09:27 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: trace.c,v 1.11 2003/04/21 02:06:52 deraadt Exp $"; #endif #define RIPCMDS @@ -342,12 +342,14 @@ addrname(naddr addr, /* in network byte order */ } bufs[NUM_BUFS]; char *s, *sp; naddr dmask; + size_t l; int i; strlcpy(bufs[bufno].str, naddr_ntoa(addr), sizeof bufs[bufno].str); bufno = (bufno+1) % NUM_BUFS; s = bufs[bufno].str; + l = sizeof(bufs[bufno].str); if (force == 1 || (force == 0 && mask != std_mask(addr))) { sp = &s[strlen(s)]; @@ -356,10 +358,10 @@ addrname(naddr addr, /* in network byte order */ if (mask + dmask == 0) { for (i = 0; i != 32 && ((1<<i) & mask) == 0; i++) continue; - (void)sprintf(sp, "/%d", 32-i); + (void)snprintf(sp, s + l - sp, "/%d", 32-i); } else { - (void)sprintf(sp, " (mask %#x)", (u_int)mask); + (void)snprintf(sp, s + l - sp, " (mask %#x)", (u_int)mask); } } @@ -488,7 +490,7 @@ trace_pair(naddr dst, int i; i = snprintf(buf, sizeof buf, "%-16s-->", addrname(dst, mask, 0)); - if (i >= sizeof buf) + if (i >= sizeof buf || i == -1) return buf; (void)snprintf(&buf[i], sizeof buf - i, "%-*s", 15+20-MAX(20,i), gate); return buf; |