svn commit: r299825 - head/sbin/routed

Pedro F. Giffuni pfg at FreeBSD.org
Sun May 15 03:04:22 UTC 2016


Author: pfg
Date: Sun May 15 03:04:21 2016
New Revision: 299825
URL: https://svnweb.freebsd.org/changeset/base/299825

Log:
  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.

Modified:
  head/sbin/routed/table.c
  head/sbin/routed/trace.c

Modified: head/sbin/routed/table.c
==============================================================================
--- head/sbin/routed/table.c	Sun May 15 03:01:40 2016	(r299824)
+++ head/sbin/routed/table.c	Sun May 15 03:04:21 2016	(r299825)
@@ -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);

Modified: head/sbin/routed/trace.c
==============================================================================
--- head/sbin/routed/trace.c	Sun May 15 03:01:40 2016	(r299824)
+++ head/sbin/routed/trace.c	Sun May 15 03:04:21 2016	(r299825)
@@ -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 byt
 	} 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 byt
 		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);
 		}
 	}
 


More information about the svn-src-all mailing list