summaryrefslogtreecommitdiff
path: root/src/cp.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2007-02-03 18:45:46 +0100
committerJim Meyering <jim@meyering.net>2007-02-03 18:45:46 +0100
commitb28a8851ed22dbf0cd123974a0c97ae0b82bec2b (patch)
tree2ee82ce576b7026f2b99268044e627daf203fb81 /src/cp.c
parent1c73876f5f7973ca41caaf0ce326254b1081713a (diff)
downloadcoreutils-b28a8851ed22dbf0cd123974a0c97ae0b82bec2b.tar.xz
* NEWS: Document fix for cp --preserve=mode.
* src/copy.c (copy_internal): Omit the group- or other-writeable permissions when creating a directory, to avoid a race condition if the special mode bits aren't right just after the directory is created. * src/cp.c (make_dir_parents_private): Likewise. * tests/cp/parent-perm-race: Test for the "cp --preserve=mode" race fix in copy.c.
Diffstat (limited to 'src/cp.c')
-rw-r--r--src/cp.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/cp.c b/src/cp.c
index aea63dce7..5759e0d07 100644
--- a/src/cp.c
+++ b/src/cp.c
@@ -435,8 +435,16 @@ make_dir_parents_private (char const *const_dir, size_t src_offset,
return false;
}
src_mode = stats.st_mode;
- omitted_permissions =
- x->preserve_ownership ? src_mode & (S_IRWXG | S_IRWXO) : 0;
+
+ /* If the ownership or special mode bits might change,
+ omit some permissions at first, so unauthorized users
+ cannot nip in before the file is ready. */
+ omitted_permissions = (src_mode
+ & (x->preserve_ownership
+ ? S_IRWXG | S_IRWXO
+ : x->preserve_mode
+ ? S_IWGRP | S_IWOTH
+ : 0));
/* POSIX says mkdir's behavior is implementation-defined when
(src_mode & ~S_IRWXUGO) != 0. However, common practice is