summaryrefslogtreecommitdiffstats
path: root/sbin/routed
diff options
context:
space:
mode:
authorpfg <pfg@FreeBSD.org>2016-05-15 03:04:21 +0000
committerpfg <pfg@FreeBSD.org>2016-05-15 03:04:21 +0000
commit825aa5d5805c303dca21ce9fc4f5b64097971655 (patch)
tree37c6a6d4203e0e11bf4149e55b3ac7c03e36b7ab /sbin/routed
parentc5c6630f07c77ca823837b255d06f6b70df2125e (diff)
downloadFreeBSD-src-825aa5d5805c303dca21ce9fc4f5b64097971655.zip
FreeBSD-src-825aa5d5805c303dca21ce9fc4f5b64097971655.tar.gz
routed(8): Misc. cleanups to squelch Coverity.
table.c: Copy into fixed size buffer. trace.c: Argument got dup2() cannot be negative. Copy into fixed size buffer. CID: 1006785, 1006786, 271301 Obtained from: NetBSD MFC after: 2 weeks.
Diffstat (limited to 'sbin/routed')
-rw-r--r--sbin/routed/table.c2
-rw-r--r--sbin/routed/trace.c12
2 files changed, 10 insertions, 4 deletions
diff --git a/sbin/routed/table.c b/sbin/routed/table.c
index 3a30071..7804d7c 100644
--- a/sbin/routed/table.c
+++ b/sbin/routed/table.c
@@ -1228,7 +1228,7 @@ read_rt(void)
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);
diff --git a/sbin/routed/trace.c b/sbin/routed/trace.c
index fcde2d4..fefa3a3 100644
--- a/sbin/routed/trace.c
+++ b/sbin/routed/trace.c
@@ -205,6 +205,8 @@ trace_close(int zap_stdio)
fclose(ftrace);
ftrace = NULL;
fd = open(_PATH_DEVNULL, O_RDWR);
+ if (fd < 0)
+ return;
if (isatty(STDIN_FILENO))
(void)dup2(fd, STDIN_FILENO);
if (isatty(STDOUT_FILENO))
@@ -439,9 +441,12 @@ addrname(naddr addr, /* in network byte order */
} 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))) {
@@ -451,10 +456,11 @@ 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);
}
}
OpenPOWER on IntegriCloud