From 7a91d69fb2995a0337085ba0c29c89354b8859e0 Mon Sep 17 00:00:00 2001 From: Andreas Rogge Date: Wed, 26 Jan 2022 10:45:28 +0100 Subject: [PATCH] Fix access mode of files created (#2530) The previous fix for this in 4a85db1 was incomplete. The intent was to mimic what `fopen()` is doing. As per standard[1] `fopen()` also sets `S_IWGRP` and `S_IWOTH` and lets the umask handle the rest. [1] https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/functions/fopen.html --- src/os.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/os.cc b/src/os.cc index d5bee7aae9815..faa84c4948503 100644 --- a/src/os.cc +++ b/src/os.cc @@ -35,9 +35,15 @@ # ifndef S_IRGRP # define S_IRGRP 0 # endif +# ifndef S_IWGRP +# define S_IWGRP 0 +# endif # ifndef S_IROTH # define S_IROTH 0 # endif +# ifndef S_IWOTH +# define S_IWOTH 0 +# endif # endif // _WIN32 #endif // FMT_USE_FCNTL @@ -214,7 +220,8 @@ file::file(cstring_view path, int oflag) { # ifdef _WIN32 using mode_t = int; # endif - mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; + constexpr mode_t mode = + S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH; # if defined(_WIN32) && !defined(__MINGW32__) fd_ = -1; FMT_POSIX_CALL(sopen_s(&fd_, path.c_str(), oflag, _SH_DENYNO, mode));