diff options
author | Markus Böck <markus.boeck02@gmail.com> | 2021-03-25 20:26:20 +0100 |
---|---|---|
committer | Markus Böck <markus.boeck02@gmail.com> | 2021-03-25 20:29:43 +0100 |
commit | c6047101ad5fc1f0c88a402bb5029949a216b2cf (patch) | |
tree | 27a0445ed801a78d13d1835c362e074153373d6d /llvm/unittests/Support/Path.cpp | |
parent | 20ad206b605530b827318cb242db7d6c04b273ea (diff) | |
download | llvm-c6047101ad5fc1f0c88a402bb5029949a216b2cf.zip llvm-c6047101ad5fc1f0c88a402bb5029949a216b2cf.tar.gz llvm-c6047101ad5fc1f0c88a402bb5029949a216b2cf.tar.bz2 |
[Support][Windows] Make sure only executables are found by sys::findProgramByName
The function utilizes Windows' SearchPathW function, which as I found out today, may also return directories. After looking at the Unix implementation of the file I found that it contains a check whether the found path is also executable. While fixing the Windows implementation, I also learned that sys::fs::access returns successfully when querying whether directories are executable, which the Unix version does not.
This patch makes both of these functions equivalent to their Unix implementation and insures that any path returned by sys::findProgramByName on Windows may only be executable, just like the Unix implementation.
The equivalent additions I have made to the Windows implementation, in the Unix implementation are here:
sys::findProgramByName: https://github.com/llvm/llvm-project/blob/39ecfe614350fa5db7b8f13f81212f8e3831a390/llvm/lib/Support/Unix/Program.inc#L90
sys::fs::access: https://github.com/llvm/llvm-project/blob/c2a84771bb63947695ea50b89160c02b36fb634d/llvm/lib/Support/Unix/Path.inc#L608
I encountered this issue when running the LLVM testsuite. Commands of the form not test ... would fail to correctly execute test.exe, which is part of GnuWin32, as it actually tried to execute a folder called test, which happened to be in a directory on my PATH.
Differential Revision: https://reviews.llvm.org/D99357
Diffstat (limited to 'llvm/unittests/Support/Path.cpp')
-rw-r--r-- | llvm/unittests/Support/Path.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp index ef18773..73f0cbb 100644 --- a/llvm/unittests/Support/Path.cpp +++ b/llvm/unittests/Support/Path.cpp @@ -1088,6 +1088,11 @@ TEST_F(FileSystemTest, DirectoryIteration) { ASSERT_NO_ERROR(fs::remove(Twine(TestDirectory) + "/reclevel")); } +TEST_F(FileSystemTest, DirectoryNotExecutable) { + ASSERT_EQ(fs::access(TestDirectory, sys::fs::AccessMode::Execute), + errc::permission_denied); +} + #ifdef LLVM_ON_UNIX TEST_F(FileSystemTest, BrokenSymlinkDirectoryIteration) { // Create a known hierarchy to recurse over. |