diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-06-17 20:35:51 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-06-17 20:35:51 +0000 |
commit | 8cd62b01ef668c61729671dee49a8b165747c40e (patch) | |
tree | 4ca936ad6ab788b10d9d24e6d734ba7ba74e58fe /llvm/lib | |
parent | 80fe668394ef140d8edc050bc34dd5d1c50596bd (diff) | |
download | bcm5719-llvm-8cd62b01ef668c61729671dee49a8b165747c40e.tar.gz bcm5719-llvm-8cd62b01ef668c61729671dee49a8b165747c40e.zip |
Only delete regular files and directories.
This ports a missing feature from PathV1.h. I am not sure how to test this
with the regular infrastructure, but an Apple bot should check this when
r183985 is reapplied.
llvm-svn: 184119
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Support/Unix/PathV2.inc | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/Support/Unix/PathV2.inc b/llvm/lib/Support/Unix/PathV2.inc index 68c17d534cd..c98c21d07cc 100644 --- a/llvm/lib/Support/Unix/PathV2.inc +++ b/llvm/lib/Support/Unix/PathV2.inc @@ -236,6 +236,22 @@ error_code remove(const Twine &path, bool &existed) { SmallString<128> path_storage; StringRef p = path.toNullTerminatedStringRef(path_storage); + struct stat buf; + if (stat(p.begin(), &buf) != 0) { + if (errno != errc::no_such_file_or_directory) + return error_code(errno, system_category()); + existed = false; + return error_code::success(); + } + + // Note: this check catches strange situations. In all cases, LLVM should + // only be involved in the creation and deletion of regular files. This + // check ensures that what we're trying to erase is a regular file. It + // effectively prevents LLVM from erasing things like /dev/null, any block + // special file, or other things that aren't "regular" files. + if (!S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) + return make_error_code(errc::operation_not_permitted); + if (::remove(p.begin()) == -1) { if (errno != errc::no_such_file_or_directory) return error_code(errno, system_category()); |