Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 28 May 2018 01:58:50 +0000 (UTC)
From:      Eric van Gyzen <vangyzen@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r334265 - head/usr.sbin/tcpdrop
Message-ID:  <201805280158.w4S1woJB055162@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: vangyzen
Date: Mon May 28 01:58:49 2018
New Revision: 334265
URL: https://svnweb.freebsd.org/changeset/base/334265

Log:
  tcpdrop: ensure NUL termination of a string
  
  strncpy did not guarantee NUL termination of the "stack" string.
  Use strlcpy instead.  While I'm here, avoid unnecessary memset
  and strnlen calls.
  
  Reported by:	Coverity
  CID:		1381035
  Sponsored by:	Dell EMC

Modified:
  head/usr.sbin/tcpdrop/tcpdrop.c

Modified: head/usr.sbin/tcpdrop/tcpdrop.c
==============================================================================
--- head/usr.sbin/tcpdrop/tcpdrop.c	Mon May 28 00:19:08 2018	(r334264)
+++ head/usr.sbin/tcpdrop/tcpdrop.c	Mon May 28 01:58:49 2018	(r334265)
@@ -73,7 +73,7 @@ main(int argc, char *argv[])
 
 	dropall = false;
 	dropallstack = false;
-	memset(stack, 0, TCP_FUNCTION_NAME_LEN_MAX);
+	stack[0] = '\0';
 	state = -1;
 
 	while ((ch = getopt(argc, argv, "alS:s:")) != -1) {
@@ -86,7 +86,7 @@ main(int argc, char *argv[])
 			break;
 		case 'S':
 			dropallstack = true;
-			strncpy(stack, optarg, TCP_FUNCTION_NAME_LEN_MAX);
+			strlcpy(stack, optarg, sizeof(stack));
 			break;
 		case 's':
 			dropallstack = true;
@@ -260,7 +260,7 @@ tcpdropall(const char *stack, int state)
 			continue;
 
 		/* If requested, skip sockets not having the requested stack. */
-		if (strnlen(stack, TCP_FUNCTION_NAME_LEN_MAX) > 0 &&
+		if (stack[0] != '\0' &&
 		    strncmp(xtp->xt_stack, stack, TCP_FUNCTION_NAME_LEN_MAX))
 			continue;
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201805280158.w4S1woJB055162>