From bddb3a481f58c9b159babffc729b0ae7796193b1 Mon Sep 17 00:00:00 2001 From: Eliane Briand Date: Tue, 4 May 2021 05:06:41 +0000 Subject: [PATCH] Respect umask when creating temporary file --- src/gromacs/utility/futil.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/gromacs/utility/futil.cpp b/src/gromacs/utility/futil.cpp index 8a54e0d864..befd2d34bb 100644 --- a/src/gromacs/utility/futil.cpp +++ b/src/gromacs/utility/futil.cpp @@ -521,6 +521,8 @@ FilePtr openLibraryFile(const char* filename, bool bAddCWD, bool bFatal) /*! \brief Use mkstemp (or similar function to make a new temporary * file and (on non-Windows systems) return a file descriptor to it. * + * Note: not thread-safe on non-Windows systems + * * \todo Use std::string and std::vector. */ static int makeTemporaryFilename(char* buf) { @@ -548,6 +550,11 @@ static int makeTemporaryFilename(char* buf) #else int fd = mkstemp(buf); + /* mkstemp creates 0600 files - respect umask instead */ + mode_t currUmask = umask(0); + umask(currUmask); + fchmod(fd, 0666 & ~currUmask); + if (fd < 0) { gmx_fatal(FARGS, "Error creating temporary file %s: %s", buf, strerror(errno)); -- 2.22.0