mirror of
https://github.com/troglobit/libite.git
synced 2026-11-09 16:21:18 +00:00
Use mkostemp() instead of insecure tmpfile() as fallback
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
1 parent
48202ef19e
commit
fae83c9be3
2 files changed
+10
-4
No files matched your search
+2
-1
@@ -9,7 +9,8 @@ All notable changes to the project are documented in this file.
|
|||||||
|
|
||||||
### Changes
|
### Changes
|
||||||
### Fixes
|
### 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
|
[v2.4.0][] - 2021-03-27
|
||||||
|
|||||||
+8
-3
@@ -26,6 +26,7 @@
|
|||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
#include <fcntl.h> /* O_TMPFILE requires -D_GNU_SOURCE */
|
#include <fcntl.h> /* O_TMPFILE requires -D_GNU_SOURCE */
|
||||||
#include <stdio.h> /* fdopen() */
|
#include <stdio.h> /* fdopen() */
|
||||||
|
#include <stdlib.h> /* mkostemp() */
|
||||||
#include <sys/stat.h> /* umask() */
|
#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);
|
fd = open(_PATH_TMP, O_TMPFILE | O_RDWR | O_EXCL | O_CLOEXEC, S_IRUSR | S_IWUSR);
|
||||||
umask(oldmask);
|
umask(oldmask);
|
||||||
if (-1 == fd) {
|
if (-1 == fd) {
|
||||||
if (errno == EOPNOTSUPP)
|
if (errno == EOPNOTSUPP) {
|
||||||
return tmpfile();
|
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+");
|
return fdopen(fd, "w+");
|
||||||
|
|||||||
Reference in new issue
Block a user