]> granicus.if.org Git - llvm/commit
[llvm-objcopy] Don't change permissions of non-regular output files
authorFangrui Song <maskray@google.com>
Thu, 11 Jul 2019 10:17:59 +0000 (10:17 +0000)
committerFangrui Song <maskray@google.com>
Thu, 11 Jul 2019 10:17:59 +0000 (10:17 +0000)
commit2a913c75fe3d8a1b2325f307b2843f069775c37a
tree0604b908217f6f25f86e6baad62571dd81107f0c
parent3fc5037f906c2d29900c8ec508bf6ac0b3a46251
[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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365753 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/Support/FileSystem.h
lib/Support/Unix/Path.inc
lib/Support/Windows/Path.inc
test/tools/llvm-objcopy/ELF/mirror-permissions-unix.test
tools/llvm-objcopy/llvm-objcopy.cpp
unittests/Support/Path.cpp