If available, use O_TMPFILE, fix insecure tempfile found by Coverity

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson 2019-11-06 07:04:06 +01:00
parent 3cff584621
commit ec06b220e4

View File

@ -2249,8 +2249,20 @@ static int cffwd(void)
static FILE *cftemp(void) static FILE *cftemp(void)
{ {
FILE *fp; FILE *fp;
#ifdef O_TMPFILE
mode_t oldmask;
int fd;
oldmask = umask(0077);
fd = open(_PATH_TMP, O_TMPFILE | O_RDWR | O_EXCL | O_CLOEXEC, S_IRUSR | S_IWUSR);
umask(oldmask);
if (-1 == fd)
return NULL;
fp = fdopen(fd, "w+");
#else
fp = tmpfile(); fp = tmpfile();
#endif
if (!fp) if (!fp)
return NULL; return NULL;