diff options
author | Fangrui Song <maskray@google.com> | 2019-07-11 10:17:59 +0000 |
---|---|---|
committer | Fangrui Song <maskray@google.com> | 2019-07-11 10:17:59 +0000 |
commit | 6dc59629570ae6fe1836cff3ff53912917d17af7 (patch) | |
tree | 163c4166284c232fd4a4b108e7c9a0dba5d32fa9 /llvm/lib/Support/Windows/Path.inc | |
parent | f9ca13cb5f05f2a1acce223e794444078584ef0d (diff) | |
download | bcm5719-llvm-6dc59629570ae6fe1836cff3ff53912917d17af7.tar.gz bcm5719-llvm-6dc59629570ae6fe1836cff3ff53912917d17af7.zip |
[llvm-objcopy] Don't change permissions of non-regular output files
There is currently an EPERM error when a regular user executes `llvm-objcopy a.o /dev/null`.
Worse, root can even change the mode bits of /dev/null.
Fix it by checking if the output file is special.
A new overload of llvm::sys::fs::setPermissions with FD as the parameter
is added. Users should provide `perm & ~umask` as the parameter if they
intend to respect umask.
The existing overload of llvm::sys::fs::setPermissions may be deleted if
we can find an implementation of fchmod() on Windows. fchmod() is
usually better than chmod() because it saves syscalls and can avoid race
condition.
Reviewed By: jakehehrlich, jhenderson
Differential Revision: https://reviews.llvm.org/D64236
llvm-svn: 365753
Diffstat (limited to 'llvm/lib/Support/Windows/Path.inc')
-rw-r--r-- | llvm/lib/Support/Windows/Path.inc | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc index 045d0b9ed58..5704930aeec 100644 --- a/llvm/lib/Support/Windows/Path.inc +++ b/llvm/lib/Support/Windows/Path.inc @@ -742,8 +742,7 @@ unsigned getUmask() { return 0; } -std::error_code setPermissions(const Twine &Path, perms Permissions, - bool /*RespectUmask*/) { +std::error_code setPermissions(const Twine &Path, perms Permissions) { SmallVector<wchar_t, 128> PathUTF16; if (std::error_code EC = widenPath(Path, PathUTF16)) return EC; @@ -774,6 +773,11 @@ std::error_code setPermissions(const Twine &Path, perms Permissions, return std::error_code(); } +std::error_code setPermissions(int FD, perms Permissions) { + // FIXME Not implemented. + return std::make_error_code(std::errc::not_supported); +} + std::error_code setLastAccessAndModificationTime(int FD, TimePoint<> AccessTime, TimePoint<> ModificationTime) { FILETIME AccessFT = toFILETIME(AccessTime); |