From 28a6ba498a3a0faf901af6734cc11ff289bd9ceb Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 7 Mar 2019 23:23:07 +0100 Subject: [PATCH] Userland: Fix broken permissions for files created by /bin/cp. When passing O_CREAT to open(), it will grab a third "mode" argument from the stack. Let's not forget to actually pass this! Also use the process umask for the created files. --- Userland/cp.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Userland/cp.cpp b/Userland/cp.cpp index d835eb38e0..3ecfae505b 100644 --- a/Userland/cp.cpp +++ b/Userland/cp.cpp @@ -34,7 +34,7 @@ int main(int argc, char** argv) return 1; } - int dst_fd = open(dst_path.characters(), O_WRONLY | O_CREAT); + int dst_fd = open(dst_path.characters(), O_WRONLY | O_CREAT, 0666); if (dst_fd < 0) { if (errno != EISDIR) { perror("open dst"); @@ -45,7 +45,7 @@ int main(int argc, char** argv) builder.append('/'); builder.append(FileSystemPath(src_path).basename()); dst_path = builder.to_string(); - dst_fd = open(dst_path.characters(), O_WRONLY | O_CREAT); + dst_fd = open(dst_path.characters(), O_WRONLY | O_CREAT, 0666); if (dst_fd < 0) { perror("open dst"); return 1; @@ -75,7 +75,9 @@ int main(int argc, char** argv) } } - rc = fchmod(dst_fd, src_stat.st_mode); + auto my_umask = umask(0); + umask(my_umask); + rc = fchmod(dst_fd, src_stat.st_mode & ~my_umask); if (rc < 0) { perror("fchmod dst"); return 1;