mirror of
https://github.com/troglobit/libite.git
synced 2026-10-17 10:39:36 +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
+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