From owner-svn-src-head@freebsd.org Mon May 28 01:58:51 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id E278CEF3DA1; Mon, 28 May 2018 01:58:50 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 81902766C7; Mon, 28 May 2018 01:58:50 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5D16E26A88; Mon, 28 May 2018 01:58:50 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w4S1woEd055163; Mon, 28 May 2018 01:58:50 GMT (envelope-from vangyzen@FreeBSD.org) Received: (from vangyzen@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w4S1woJB055162; Mon, 28 May 2018 01:58:50 GMT (envelope-from vangyzen@FreeBSD.org) Message-Id: <201805280158.w4S1woJB055162@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: vangyzen set sender to vangyzen@FreeBSD.org using -f From: Eric van Gyzen Date: Mon, 28 May 2018 01:58:50 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334265 - head/usr.sbin/tcpdrop X-SVN-Group: head X-SVN-Commit-Author: vangyzen X-SVN-Commit-Paths: head/usr.sbin/tcpdrop X-SVN-Commit-Revision: 334265 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 28 May 2018 01:58:51 -0000 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;