From 01a9a2a5a8c56ce8699616a608a28de4e537ff56 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 26 Apr 2016 10:32:34 +0200 Subject: trafgen: Use mkostemp_or_die() to create unique temporary file Use the mkostemp_or_die() wrapper introduced in commit a87f181bd836 ("ioops: Add mkostemp_or_die") to safely create a unique temporary file instead of using rand() to manually create a (potentially unsafe) temporary filename. Signed-off-by: Tobias Klauser --- trafgen.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'trafgen.c') diff --git a/trafgen.c b/trafgen.c index 949f909..002b01a 100644 --- a/trafgen.c +++ b/trafgen.c @@ -417,15 +417,9 @@ static struct cpu_stats *setup_shared_var(unsigned int cpus) char *zbuff, file[256]; struct cpu_stats *buff; + slprintf(file, sizeof(file), ".tmp_mmap.XXXXXX"); + fd = mkostemp_or_die(file, O_RDWR | O_CREAT | O_TRUNC); zbuff = xzmalloc(len); - slprintf(file, sizeof(file), ".tmp_mmap.%u", (unsigned int) rand()); - - fd = creat(file, S_IRUSR | S_IWUSR); - bug_on(fd < 0); - close(fd); - - fd = open_or_die_m(file, O_RDWR | O_CREAT | O_TRUNC, - S_IRUSR | S_IWUSR); write_or_die(fd, zbuff, len); xfree(zbuff); -- cgit v1.2.3-54-g00ecf