[lld] r307092 - ELF: Only unlink regular files

Tom Stellard via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 4 09:03:34 PDT 2017


Author: tstellar
Date: Tue Jul  4 09:03:34 2017
New Revision: 307092

URL: http://llvm.org/viewvc/llvm-project?rev=307092&view=rev
Log:
ELF: Only unlink regular files

Summary:
If the output file is a character file (e.g. /dev/null) unlinking it could
potentially destabilize the user's system.  For example,
unlinking causes `lld %input -o /dev/null` to replace /dev/null with a
regular file, which will lead to unexpected behavior in other programs
that read from /dev/null, and worse than expected peformance for
programs that write to /dev/null.

This makes it possible to run the test-release.sh script as root.
Prior to this patch, the ELF/basic.s test would replace
/dev/null with a regular file, which would cause crashes in llvm
test-suite programs that piped /dev/null to stdin.

For example, if you run the test-relase.sh script as root,

Reviewers: ruiu

Reviewed By: ruiu

Subscribers: emaste, llvm-commits

Differential Revision: https://reviews.llvm.org/D34917

Modified:
    lld/trunk/ELF/Filesystem.cpp

Modified: lld/trunk/ELF/Filesystem.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Filesystem.cpp?rev=307092&r1=307091&r2=307092&view=diff
==============================================================================
--- lld/trunk/ELF/Filesystem.cpp (original)
+++ lld/trunk/ELF/Filesystem.cpp Tue Jul  4 09:03:34 2017
@@ -38,7 +38,8 @@ using namespace lld::elf;
 // This function spawns a background thread to call unlink.
 // The calling thread returns almost immediately.
 void elf::unlinkAsync(StringRef Path) {
-  if (!Config->Threads || !sys::fs::exists(Config->OutputFile))
+  if (!Config->Threads || !sys::fs::exists(Config->OutputFile) ||
+      !sys::fs::is_regular_file(Config->OutputFile))
     return;
 
   // First, rename Path to avoid race condition. We cannot remove




More information about the llvm-commits mailing list