mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-25 22:25:58 +01:00
util/create_tmpfile: set restrictive umask for these files
Even if the file is removed right away, a race with someone using inotify is definitely possible, so play safe and restrict umask for our tmpfiles Found through static analysis.
This commit is contained in:
parent
efef54ccf5
commit
399de4d11b
1 changed files with 3 additions and 0 deletions
|
@ -29,6 +29,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "util/os-compatibility.h"
|
#include "util/os-compatibility.h"
|
||||||
|
@ -61,6 +62,7 @@ int create_tmpfile_cloexec(char *tmpname)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
|
mode_t prev_umask = umask(0066);
|
||||||
#ifdef HAVE_MKOSTEMP
|
#ifdef HAVE_MKOSTEMP
|
||||||
fd = mkostemp(tmpname, O_CLOEXEC);
|
fd = mkostemp(tmpname, O_CLOEXEC);
|
||||||
if (fd >= 0)
|
if (fd >= 0)
|
||||||
|
@ -72,6 +74,7 @@ int create_tmpfile_cloexec(char *tmpname)
|
||||||
unlink(tmpname);
|
unlink(tmpname);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
umask(prev_umask);
|
||||||
|
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue