diff options
| author | Kaelyn Uhrain <rikka@google.com> | 2012-06-20 20:21:33 +0000 |
|---|---|---|
| committer | Kaelyn Uhrain <rikka@google.com> | 2012-06-20 20:21:33 +0000 |
| commit | 23fb5c3e939f2930435a6323bc937da8e2d439d1 (patch) | |
| tree | 4e8ba50000f4a31609e6e925715ea3b18b868ef5 /llvm/lib/Support/MemoryBuffer.cpp | |
| parent | dbb7ae54b87e27920df7f4b3c7b3a87533b39125 (diff) | |
| download | bcm5719-llvm-23fb5c3e939f2930435a6323bc937da8e2d439d1.tar.gz bcm5719-llvm-23fb5c3e939f2930435a6323bc937da8e2d439d1.zip | |
Check that a file is not a directory before reading it into a MemoryBuffer.
llvm-svn: 158841
Diffstat (limited to 'llvm/lib/Support/MemoryBuffer.cpp')
| -rw-r--r-- | llvm/lib/Support/MemoryBuffer.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/llvm/lib/Support/MemoryBuffer.cpp b/llvm/lib/Support/MemoryBuffer.cpp index 16e5c7a9f72..fabf1406acb 100644 --- a/llvm/lib/Support/MemoryBuffer.cpp +++ b/llvm/lib/Support/MemoryBuffer.cpp @@ -17,6 +17,7 @@ #include "llvm/Config/config.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/Errno.h" +#include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/Process.h" #include "llvm/Support/Program.h" @@ -214,6 +215,14 @@ error_code MemoryBuffer::getFile(const char *Filename, OwningPtr<MemoryBuffer> &result, int64_t FileSize, bool RequiresNullTerminator) { + // First check that the "file" is not a directory + bool is_dir = false; + error_code err = sys::fs::is_directory(Filename, is_dir); + if (err) + return err; + else if (is_dir) + return make_error_code(errc::is_a_directory); + int OpenFlags = O_RDONLY; #ifdef O_BINARY OpenFlags |= O_BINARY; // Open input file in binary mode on win32. |

