Use mkostemp() instead of insecure tmpfile() as fallback

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2021-10-06 17:51:07 +02:00
parent 48202ef19e
commit fae83c9be3
2 changed files with 10 additions and 4 deletions
+2 -1
View File
@@ -9,7 +9,8 @@ All notable changes to the project are documented in this file.
### Changes
### Fixes
- Fix issue with `tempfile()` returning EOPNOTSUPP on Azure
- Fix issue with `tempfile()` returning EOPNOTSUPP on Azure, use
fallback to `mkostemp()` with `O_CLOEXEC` flag set
[v2.4.0][] - 2021-03-27
+8 -3
View File
@@ -26,6 +26,7 @@
#include <paths.h>
#include <fcntl.h> /* O_TMPFILE requires -D_GNU_SOURCE */
#include <stdio.h> /* fdopen() */
#include <stdlib.h> /* mkostemp() */
#include <sys/stat.h> /* umask() */
/**
@@ -53,10 +54,14 @@ FILE *tempfile(void)
fd = open(_PATH_TMP, O_TMPFILE | O_RDWR | O_EXCL | O_CLOEXEC, S_IRUSR | S_IWUSR);
umask(oldmask);
if (-1 == fd) {
if (errno == EOPNOTSUPP)
return tmpfile();
if (errno == EOPNOTSUPP) {
char nm[15] = _PATH_TMP "XXXXXXXX";
return NULL;
fd = mkostemp(nm, O_CLOEXEC);
if (-1 == fd)
return NULL;
} else
return NULL;
}
return fdopen(fd, "w+");