From 1b374915214356cdc76549012e48f7ec0def049c Mon Sep 17 00:00:00 2001 From: midipix Date: Thu, 21 Mar 2024 22:50:08 +0000 Subject: tpax_tmpfile(): refactor code and template, eliminate use of rand_r(). --- src/internal/tpax_tmpfile_impl.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/internal/tpax_tmpfile_impl.c b/src/internal/tpax_tmpfile_impl.c index 56d5c92..9dd9d40 100644 --- a/src/internal/tpax_tmpfile_impl.c +++ b/src/internal/tpax_tmpfile_impl.c @@ -5,12 +5,16 @@ /**************************************************************/ #define _GNU_SOURCE +#include #include #include #include #include #include #include +#include + +#define PPRIX64 "%"PRIx64 /* mkostemp might be guarded by non-standard macros */ /* unless HAVE_NO_MKOSTEMP, assume it is available */ @@ -54,8 +58,8 @@ static int tpax_mkostemp(char * tmplate) int tpax_tmpfile(void) { int fd; - unsigned seed; - char tmplate[64]; + void * addr; + char tmplate[128]; /* try with __fs_tmpfile() */ if ((fd = tpax_tmpfile_by_framework()) >= 0) @@ -66,10 +70,18 @@ int tpax_tmpfile(void) return fd; /* fallback to mk{o}stemp */ - seed = getpid(); + addr = tmplate; memset(tmplate,0,sizeof(tmplate)); - snprintf(tmplate,sizeof(tmplate),"/tmp/tpax_%d_%d_%d_XXXXXXXXXXXX", - getppid(),getpid(),rand_r(&seed)); + snprintf(tmplate,sizeof(tmplate), + "/tmp/" + ".tpax.tmpfile" + ".time."PPRIX64 + ".salt.%p" + ".pid.%d" + ".XXXXXXXXXXXX", + time(0), + addr, + getpid()); return tpax_mkostemp(tmplate); } -- cgit v1.2.3