mirror of
https://github.com/troglobit/libite.git
synced 2026-10-08 00:04:27 +07:00
Use mkostemp() instead of insecure tmpfile() as fallback
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
+2
-1
@@ -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
@@ -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+");
|
||||
|
||||
Reference in New Issue
Block a user