summaryrefslogtreecommitdiff
path: root/src/fileio.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2011-07-18 14:01:36 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2011-07-18 14:01:36 -0700
commit15e3a074a6ebdcefd828a1ba14a5a12ff9921034 (patch)
treec8bfe3d2fc0cede440a408876040910563de678e /src/fileio.c
parent41bed37d157e1a7bdc519bfc3668d59be5b05402 (diff)
downloademacs-15e3a074a6ebdcefd828a1ba14a5a12ff9921034.tar.gz
* fileio.c (Fcopy_file) [!MSDOS]: Tighten created file's mask.
This fixes some race conditions on the permissions of any newly created file.
Diffstat (limited to 'src/fileio.c')
-rw-r--r--src/fileio.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/fileio.c b/src/fileio.c
index fb2c081ae5c..3e1aa54462f 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -1937,10 +1937,19 @@ on the system, we copy the SELinux context of FILE to NEWNAME. */)
| (NILP (ok_if_already_exists) ? O_EXCL : 0),
S_IREAD | S_IWRITE);
#else /* not MSDOS */
- ofd = emacs_open (SSDATA (encoded_newname),
- O_WRONLY | O_TRUNC | O_CREAT
- | (NILP (ok_if_already_exists) ? O_EXCL : 0),
- 0666);
+ {
+ int new_mask = 0666;
+ if (input_file_statable_p)
+ {
+ if (!NILP (preserve_uid_gid))
+ new_mask = 0600;
+ new_mask &= st.st_mode;
+ }
+ ofd = emacs_open (SSDATA (encoded_newname),
+ (O_WRONLY | O_TRUNC | O_CREAT
+ | (NILP (ok_if_already_exists) ? O_EXCL : 0)),
+ new_mask);
+ }
#endif /* not MSDOS */
if (ofd < 0)
report_file_error ("Opening output file", Fcons (newname, Qnil));