From owner-svn-src-head@freebsd.org Thu Aug 16 21:36:22 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 4254510776AD; Thu, 16 Aug 2018 21:36:22 +0000 (UTC) (envelope-from asomers@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 DBAAC7A6D2; Thu, 16 Aug 2018 21:36:21 +0000 (UTC) (envelope-from asomers@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 B6CFD1F1EB; Thu, 16 Aug 2018 21:36:21 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w7GLaLob038126; Thu, 16 Aug 2018 21:36:21 GMT (envelope-from asomers@FreeBSD.org) Received: (from asomers@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w7GLaJ51038118; Thu, 16 Aug 2018 21:36:19 GMT (envelope-from asomers@FreeBSD.org) Message-Id: <201808162136.w7GLaJ51038118@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: asomers set sender to asomers@FreeBSD.org using -f From: Alan Somers Date: Thu, 16 Aug 2018 21:36:19 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r337929 - in head/tests/sys: aio file kern kern/pipe posixshm X-SVN-Group: head X-SVN-Commit-Author: asomers X-SVN-Commit-Paths: in head/tests/sys: aio file kern kern/pipe posixshm X-SVN-Commit-Revision: 337929 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.27 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: Thu, 16 Aug 2018 21:36:22 -0000 Author: asomers Date: Thu Aug 16 21:36:19 2018 New Revision: 337929 URL: https://svnweb.freebsd.org/changeset/base/337929 Log: Fix Coverity warnings about mkstemp in tests umask(2) should always be used prior to mkstemp(3) so the temporary file won't be created with insecure permissions. Reported by: Coverity CID: 1331605 1347173 1375366 1339800 1331604 1296056 1296060 CID: 1296057 1296062 MFC after: 2 weeks Modified: head/tests/sys/aio/aio_kqueue_test.c head/tests/sys/aio/lio_kqueue_test.c head/tests/sys/file/dup_test.c head/tests/sys/file/flock_helper.c head/tests/sys/kern/kern_copyin.c head/tests/sys/kern/pipe/pipe_overcommit2_test.c head/tests/sys/kern/ptrace_test.c head/tests/sys/kern/unix_passfd_test.c head/tests/sys/posixshm/posixshm_test.c Modified: head/tests/sys/aio/aio_kqueue_test.c ============================================================================== --- head/tests/sys/aio/aio_kqueue_test.c Thu Aug 16 19:48:07 2018 (r337928) +++ head/tests/sys/aio/aio_kqueue_test.c Thu Aug 16 21:36:19 2018 (r337929) @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -90,6 +91,7 @@ main (int argc, char *argv[]) if (argc == 1) { strcpy(pathname, PATH_TEMPLATE); + umask(0077); fd = mkstemp(pathname); file = pathname; tmp_file = 1; Modified: head/tests/sys/aio/lio_kqueue_test.c ============================================================================== --- head/tests/sys/aio/lio_kqueue_test.c Thu Aug 16 19:48:07 2018 (r337928) +++ head/tests/sys/aio/lio_kqueue_test.c Thu Aug 16 21:36:19 2018 (r337929) @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -86,6 +87,7 @@ main(int argc, char *argv[]) if (argc == 1) { strcpy(pathname, PATH_TEMPLATE); + umask(0077); fd = mkstemp(pathname); file = pathname; tmp_file = 1; Modified: head/tests/sys/file/dup_test.c ============================================================================== --- head/tests/sys/file/dup_test.c Thu Aug 16 19:48:07 2018 (r337928) +++ head/tests/sys/file/dup_test.c Thu Aug 16 21:36:19 2018 (r337929) @@ -50,6 +50,7 @@ * open files limit work. */ +#include #include #include #include @@ -68,6 +69,7 @@ getafile(void) int fd; char temp[] = "/tmp/dup2XXXXXXXXX"; + umask(0077); if ((fd = mkstemp(temp)) < 0) err(1, "mkstemp"); remove(temp); Modified: head/tests/sys/file/flock_helper.c ============================================================================== --- head/tests/sys/file/flock_helper.c Thu Aug 16 19:48:07 2018 (r337928) +++ head/tests/sys/file/flock_helper.c Thu Aug 16 21:36:19 2018 (r337929) @@ -92,6 +92,7 @@ make_file(const char *pathname, off_t sz) filename = malloc(len); strcpy(filename, pathname); strcat(filename, template); + umask(0077); fd = mkstemp(filename); if (fd < 0) err(1, "mkstemp"); Modified: head/tests/sys/kern/kern_copyin.c ============================================================================== --- head/tests/sys/kern/kern_copyin.c Thu Aug 16 19:48:07 2018 (r337928) +++ head/tests/sys/kern/kern_copyin.c Thu Aug 16 21:36:19 2018 (r337929) @@ -31,6 +31,7 @@ __FBSDID("$FreeBSD$"); #include +#include #include #include #include @@ -69,6 +70,7 @@ ATF_TC_BODY(kern_copyin, tc) atf_tc_skip("Platform is not supported."); #endif + umask(0077); scratch_file = mkstemp(template); ATF_REQUIRE(scratch_file != -1); unlink(template); Modified: head/tests/sys/kern/pipe/pipe_overcommit2_test.c ============================================================================== --- head/tests/sys/kern/pipe/pipe_overcommit2_test.c Thu Aug 16 19:48:07 2018 (r337928) +++ head/tests/sys/kern/pipe/pipe_overcommit2_test.c Thu Aug 16 21:36:19 2018 (r337929) @@ -27,6 +27,7 @@ */ #include +#include #include #include #include @@ -50,6 +51,7 @@ main(void) lastfd = -1; + umask(0077); if (mkstemp(template) == -1) err(1, "mkstemp failed"); Modified: head/tests/sys/kern/ptrace_test.c ============================================================================== --- head/tests/sys/kern/ptrace_test.c Thu Aug 16 19:48:07 2018 (r337928) +++ head/tests/sys/kern/ptrace_test.c Thu Aug 16 21:36:19 2018 (r337929) @@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -3347,6 +3348,7 @@ ATF_TC_BODY(ptrace__PT_ATTACH_with_SBDRY_thread, tc) ATF_REQUIRE(pthread_barrier_init(&barrier, &battr, 2) == 0); (void)snprintf(tmpfile, sizeof(tmpfile), "./ptrace.XXXXXX"); + umask(0077); fd = mkstemp(tmpfile); ATF_REQUIRE(fd >= 0); Modified: head/tests/sys/kern/unix_passfd_test.c ============================================================================== --- head/tests/sys/kern/unix_passfd_test.c Thu Aug 16 19:48:07 2018 (r337928) +++ head/tests/sys/kern/unix_passfd_test.c Thu Aug 16 21:36:19 2018 (r337929) @@ -87,6 +87,7 @@ tempfile(int *fdp) snprintf(path, PATH_MAX, "%s/unix_passfd.XXXXXXXXXXXXXXX", getenv("TMPDIR") == NULL ? "/tmp" : getenv("TMPDIR")); + umask(0077); fd = mkstemp(path); ATF_REQUIRE_MSG(fd != -1, "mkstemp(%s) failed", path); (void)unlink(path); Modified: head/tests/sys/posixshm/posixshm_test.c ============================================================================== --- head/tests/sys/posixshm/posixshm_test.c Thu Aug 16 19:48:07 2018 (r337928) +++ head/tests/sys/posixshm/posixshm_test.c Thu Aug 16 21:36:19 2018 (r337929) @@ -54,6 +54,7 @@ gen_test_path(void) snprintf(test_path, sizeof(test_path), "%s/tmp.XXXXXX", getenv("TMPDIR") == NULL ? "/tmp" : getenv("TMPDIR")); test_path[sizeof(test_path) - 1] = '\0'; + umask(0077); ATF_REQUIRE_MSG(mkstemp(test_path) != -1, "mkstemp failed; errno=%d", errno); ATF_REQUIRE_MSG(unlink(test_path) == 0,