Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/routed strcpy/sprintf cleanup. from openbsd
details: https://anonhg.NetBSD.org/src/rev/136ed04a8d05
branches: trunk
changeset: 546158:136ed04a8d05
user: itojun <itojun%NetBSD.org@localhost>
date: Mon Apr 21 08:54:42 2003 +0000
description:
strcpy/sprintf cleanup. from openbsd
diffstat:
sbin/routed/main.c | 6 +++---
sbin/routed/parms.c | 8 ++++----
sbin/routed/table.c | 28 ++++++++++++++++++----------
sbin/routed/trace.c | 26 +++++++++++++++++---------
4 files changed, 42 insertions(+), 26 deletions(-)
diffs (211 lines):
diff -r 814a253959ca -r 136ed04a8d05 sbin/routed/main.c
--- a/sbin/routed/main.c Mon Apr 21 08:41:28 2003 +0000
+++ b/sbin/routed/main.c Mon Apr 21 08:54:42 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.31 2002/11/30 04:04:23 christos Exp $ */
+/* $NetBSD: main.c,v 1.32 2003/04/21 08:54:42 itojun Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@@ -46,7 +46,7 @@
"The Regents of the University of California."
" All rights reserved.\n");
#ifdef __NetBSD__
-__RCSID("$NetBSD: main.c,v 1.31 2002/11/30 04:04:23 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.32 2003/04/21 08:54:42 itojun Exp $");
#elif defined(__FreeBSD__)
__RCSID("$FreeBSD$");
#else
@@ -321,7 +321,7 @@
if (tracename != 0) {
- strncpy(inittracename, tracename, sizeof(inittracename)-1);
+ strlcpy(inittracename, tracename, sizeof(inittracename));
set_tracefile(inittracename, "%s", -1);
} else {
tracelevel_msg("%s", -1); /* turn on tracing to stdio */
diff -r 814a253959ca -r 136ed04a8d05 sbin/routed/parms.c
--- a/sbin/routed/parms.c Mon Apr 21 08:41:28 2003 +0000
+++ b/sbin/routed/parms.c Mon Apr 21 08:54:42 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: parms.c,v 1.18 2003/04/15 08:20:17 itojun Exp $ */
+/* $NetBSD: parms.c,v 1.19 2003/04/21 08:54:42 itojun Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -38,7 +38,7 @@
#include <sys/stat.h>
#ifdef __NetBSD__
-__RCSID("$NetBSD: parms.c,v 1.18 2003/04/15 08:20:17 itojun Exp $");
+__RCSID("$NetBSD: parms.c,v 1.19 2003/04/21 08:54:42 itojun Exp $");
#elif defined(__FreeBSD__)
__RCSID("$FreeBSD$");
#else
@@ -283,7 +283,7 @@
* tables to prevent overriding them with something
* else.
*/
- strcpy(qual,"external");
+ strlcpy(qual, "external", sizeof(qual));
state = IS_REMOTE | IS_PASSIVE | IS_EXTERNAL;
if (metric == 0)
metric = 1;
@@ -680,7 +680,7 @@
if (parm.parm_name[0] != '\0'
|| strlen(buf) > IF_NAME_LEN)
return bad_str(tgt);
- strcpy(parm.parm_name, buf);
+ strlcpy(parm.parm_name, buf, sizeof(parm.parm_name));
} else if (PARSEQ("addr")) {
/* This is a bad idea, because the address based
diff -r 814a253959ca -r 136ed04a8d05 sbin/routed/table.c
--- a/sbin/routed/table.c Mon Apr 21 08:41:28 2003 +0000
+++ b/sbin/routed/table.c Mon Apr 21 08:54:42 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: table.c,v 1.19 2003/04/15 08:20:18 itojun Exp $ */
+/* $NetBSD: table.c,v 1.20 2003/04/21 08:54:42 itojun Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@@ -36,7 +36,7 @@
#include "defs.h"
#ifdef __NetBSD__
-__RCSID("$NetBSD: table.c,v 1.19 2003/04/15 08:20:18 itojun Exp $");
+__RCSID("$NetBSD: table.c,v 1.20 2003/04/21 08:54:42 itojun Exp $");
#elif defined(__FreeBSD__)
__RCSID("$FreeBSD$");
#else
@@ -1231,10 +1231,13 @@
continue; /* ignore compat message */
#endif
- strcpy(str, rtm_type_name(m.r.rtm.rtm_type));
+ 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 %d",m.r.rtm.rtm_pid);
+ if (m.r.rtm.rtm_type <= RTM_CHANGE) {
+ snprintf(strp, str + sizeof(str) - strp,
+ " from pid %d",m.r.rtm.rtm_pid);
+ strp += strlen(strp);
+ }
rt_xaddrs(&info, m.r.addrs, &m.r.addrs[RTAX_MAX],
m.r.rtm.rtm_addrs);
@@ -1256,8 +1259,9 @@
? 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", str);
@@ -1278,14 +1282,18 @@
if (get_info_gate(&INFO_GATE(&info), &gate_sin)) {
gate = S_ADDR(INFO_GATE(&info));
- strp += sprintf(strp, " --> %s", naddr_ntoa(gate));
+ snprintf(strp, str + sizeof(str) - strp,
+ " --> %s", naddr_ntoa(gate));
+ strp += strlen(strp);
} else {
gate = 0;
}
if (INFO_AUTHOR(&info) != 0)
- strp += sprintf(strp, " by authority of %s",
- saddr_ntoa(INFO_AUTHOR(&info)));
+ 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 -r 814a253959ca -r 136ed04a8d05 sbin/routed/trace.c
--- a/sbin/routed/trace.c Mon Apr 21 08:41:28 2003 +0000
+++ b/sbin/routed/trace.c Mon Apr 21 08:54:42 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: trace.c,v 1.27 2002/11/30 04:04:24 christos Exp $ */
+/* $NetBSD: trace.c,v 1.28 2003/04/21 08:54:42 itojun Exp $ */
/*
* Copyright (c) 1983, 1988, 1993
@@ -41,7 +41,7 @@
#include <fcntl.h>
#ifdef __NetBSD__
-__RCSID("$NetBSD: trace.c,v 1.27 2002/11/30 04:04:24 christos Exp $");
+__RCSID("$NetBSD: trace.c,v 1.28 2003/04/21 08:54:42 itojun Exp $");
#elif defined(__FreeBSD__)
__RCSID("$FreeBSD$");
#else
@@ -135,7 +135,8 @@
struct in_addr addr;
addr.s_addr = a;
- s = strcpy(bufs[bufno].str, inet_ntoa(addr));
+ strlcpy(bufs[bufno].str, inet_ntoa(addr), sizeof(bufs[bufno].str));
+ s = bufs[bufno].str;
bufno = (bufno+1) % NUM_BUFS;
return s;
#undef NUM_BUFS
@@ -372,7 +373,7 @@
trace_close(file_trace = 1);
if (fn != savetracename)
- strncpy(savetracename, fn, sizeof(savetracename)-1);
+ strlcpy(savetracename, fn, sizeof(savetracename));
ftrace = n_ftrace;
fflush(stdout);
@@ -445,9 +446,12 @@
} bufs[NUM_BUFS];
char *s, *sp;
naddr dmask;
+ size_t l;
int i;
- s = strcpy(bufs[bufno].str, naddr_ntoa(addr));
+ strlcpy(bufs[bufno].str, naddr_ntoa(addr), sizeof(bufs[bufno].str));
+ s = bufs[bufno].str;
+ l = sizeof(bufs[bufno].str);
bufno = (bufno+1) % NUM_BUFS;
if (force == 1 || (force == 0 && mask != std_mask(addr))) {
@@ -457,10 +461,11 @@
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);
}
}
@@ -590,8 +595,11 @@
+3*4+3+1]; /* "xxx.xxx.xxx.xxx" */
int i;
- i = sprintf(buf, "%-16s-->", addrname(dst, mask, 0));
- (void)sprintf(&buf[i], "%-*s", 15+20-MAX(20,i), naddr_ntoa(gate));
+ i = snprintf(buf, sizeof(buf), "%-16s-->", addrname(dst, mask, 0));
+ if (i >= sizeof(buf) || i < 0)
+ return buf;
+ (void)snprintf(&buf[i], sizeof(buf) - i, "%-*s", 15+20-MAX(20, i),
+ naddr_ntoa(gate));
return buf;
}
Home |
Main Index |
Thread Index |
Old Index