summaryrefslogtreecommitdiff
path: root/lib/Support/PathV2.cpp
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2012-06-19 05:29:57 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2012-06-19 05:29:57 +0000
commitb51c8e9bb5769ed17261392ff4222ad3a6668285 (patch)
tree088d38e2613f28277606050f05325c31a0faf5fb /lib/Support/PathV2.cpp
parentbde801b2a7e20f3de62cacc3ef643cf0ed6e2c27 (diff)
downloadllvm-b51c8e9bb5769ed17261392ff4222ad3a6668285.tar.gz
llvm-b51c8e9bb5769ed17261392ff4222ad3a6668285.tar.bz2
llvm-b51c8e9bb5769ed17261392ff4222ad3a6668285.tar.xz
[Support/PathV2] Fix out of bounds access in identify_magic when the file is empty.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158704 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/PathV2.cpp')
-rw-r--r--lib/Support/PathV2.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/lib/Support/PathV2.cpp b/lib/Support/PathV2.cpp
index e2a69a650d..46571c049f 100644
--- a/lib/Support/PathV2.cpp
+++ b/lib/Support/PathV2.cpp
@@ -744,6 +744,8 @@ error_code has_magic(const Twine &path, const Twine &magic, bool &result) {
/// @brief Identify the magic in magic.
file_magic identify_magic(StringRef magic) {
+ if (magic.size() < 4)
+ return file_magic::unknown;
switch ((unsigned char)magic[0]) {
case 0xDE: // 0x0B17C0DE = BC wraper
if (magic[1] == (char)0xC0 && magic[2] == (char)0x17 &&