From 399de4d11bb36b71fdfb5f1a06e74cf7c4e6831c Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 30 Jun 2018 10:55:33 +0900 Subject: 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. --- util/os-compatibility.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'util') diff --git a/util/os-compatibility.c b/util/os-compatibility.c index bd3067d2..38333605 100644 --- a/util/os-compatibility.c +++ b/util/os-compatibility.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include "util/os-compatibility.h" @@ -61,6 +62,7 @@ int create_tmpfile_cloexec(char *tmpname) { int fd; + mode_t prev_umask = umask(0066); #ifdef HAVE_MKOSTEMP fd = mkostemp(tmpname, O_CLOEXEC); if (fd >= 0) @@ -72,6 +74,7 @@ int create_tmpfile_cloexec(char *tmpname) unlink(tmpname); } #endif + umask(prev_umask); return fd; } -- cgit v1.2.3