summaryrefslogtreecommitdiffstats
path: root/cmd/ztest
diff options
context:
space:
mode:
authorBrian Behlendorf <[email protected]>2012-10-04 11:36:52 -0700
committerBrian Behlendorf <[email protected]>2012-10-04 13:19:10 -0700
commitfacbbe436670b4910475fb937a26468f7178b541 (patch)
tree56c839ef4d32a358e2760b8c72e83023df8d5bc0 /cmd/ztest
parent483106eb71b1886c824951b3a35d89d47d41405e (diff)
Replace tempnam() with mkstemp()
The use of tempnam() is racy and it should be avoided in favor of mkstemp(). According to the Linux tempnam(3) man page. "Although tempnam() generates names that are difficult to guess, it is nevertheless possible that between the time that tempnam() returns a pathname, and the time that the program opens it, another program might create that pathname using open(2), or create it as a symbolic link. This can lead to security holes. To avoid such possibilities, use the open(2) O_EXCL flag to open the pathname. Or better yet, use mkstemp(3) or tmpfile(3)." This issue was flagged by gcc. ztest.o: In function `setup_data_fd': cmd/ztest/ztest.c:5822: warning: the use of `tempnam' is dangerous, better use `mkstemp' Signed-off-by: Brian Behlendorf <[email protected]>
Diffstat (limited to 'cmd/ztest')
-rw-r--r--cmd/ztest/ztest.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/cmd/ztest/ztest.c b/cmd/ztest/ztest.c
index 65cbbe0b4..bc2f56fb8 100644
--- a/cmd/ztest/ztest.c
+++ b/cmd/ztest/ztest.c
@@ -5819,11 +5819,11 @@ ztest_init(ztest_shared_t *zs)
static void
setup_data_fd(void)
{
- char *tmp = tempnam(NULL, NULL);
- ztest_fd_data = open(tmp, O_RDWR | O_CREAT, 0700);
+ static char ztest_name_data[] = "/tmp/ztest.data.XXXXXX";
+
+ ztest_fd_data = mkstemp(ztest_name_data);
ASSERT3S(ztest_fd_data, >=, 0);
- (void) unlink(tmp);
- free(tmp);
+ (void) unlink(ztest_name_data);
}
static int