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
This commit is contained in:
parent
0e72f30a06
commit
6c56bcb7d1
@ -36,6 +36,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/event.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <aio.h>
|
||||
#include <err.h>
|
||||
@ -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;
|
||||
|
@ -32,6 +32,7 @@
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/event.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <aio.h>
|
||||
#include <fcntl.h>
|
||||
@ -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;
|
||||
|
@ -50,6 +50,7 @@
|
||||
* open files limit work.
|
||||
*/
|
||||
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
@ -68,6 +69,7 @@ getafile(void)
|
||||
int fd;
|
||||
|
||||
char temp[] = "/tmp/dup2XXXXXXXXX";
|
||||
umask(0077);
|
||||
if ((fd = mkstemp(temp)) < 0)
|
||||
err(1, "mkstemp");
|
||||
remove(temp);
|
||||
|
@ -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");
|
||||
|
@ -31,6 +31,7 @@
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
@ -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);
|
||||
|
@ -27,6 +27,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/stat.h>
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
@ -50,6 +51,7 @@ main(void)
|
||||
|
||||
lastfd = -1;
|
||||
|
||||
umask(0077);
|
||||
if (mkstemp(template) == -1)
|
||||
err(1, "mkstemp failed");
|
||||
|
||||
|
@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$");
|
||||
#include <sys/ptrace.h>
|
||||
#include <sys/queue.h>
|
||||
#include <sys/runq.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/user.h>
|
||||
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user