mirror of
https://github.com/troglobit/libite.git
synced 2026-10-14 10:19:31 +00:00
Fix copyfile() not preserving source mode with restrictive umask
copyfile() passes the source mode to open(2), which applies the umask, so a 0644 file copied with umask 0027 ends up 0640. Apply the source mode with fchmod() after creating the destination. Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
3 files changed
+34
-1
No files matched your search
@@ -208,12 +208,20 @@ ssize_t copyfile(const char *src, const char *dst, int len, int opt)
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* open(2) applies umask, we want the source file mode */
|
||||
if (fchmod(out, st.st_mode & 07777)) {
|
||||
saved_errno = errno;
|
||||
size = -1;
|
||||
goto close_exit;
|
||||
}
|
||||
|
||||
size = do_copy(in, out, num, buffer, BUFSIZ);
|
||||
if (size < 0)
|
||||
saved_errno = errno;
|
||||
else if (keep_mtim)
|
||||
set_mtime(in, out);
|
||||
|
||||
close_exit:
|
||||
close(out);
|
||||
close(in);
|
||||
|
||||
|
||||
Reference in new issue
Block a user