[mkstemp] set umask

This commit is contained in:
akallabeth
2025-03-11 09:13:22 +01:00
parent 2b26cf74e0
commit ca964f7c7d
2 changed files with 28 additions and 3 deletions

View File

@@ -59,6 +59,7 @@
#include <stdio.h>
#include <string.h>
#include <sys/epoll.h>
#include <sys/stat.h>
#include <uwac/config.h>
@@ -178,6 +179,14 @@ int uwac_os_epoll_create_cloexec(void)
return set_cloexec_or_close(fd);
}
static int secure_mkstemp(char* tmpname)
{
const mode_t mask = umask(S_IRWXU);
int fd = mkstemp(tmpname);
(void)umask(mask);
return fd;
}
static int create_tmpfile_cloexec(char* tmpname)
{
int fd = 0;
@@ -190,7 +199,7 @@ static int create_tmpfile_cloexec(char* tmpname)
unlink(tmpname);
#else
fd = mkstemp(tmpname);
fd = secure_mkstemp(tmpname);
if (fd >= 0)
{