diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-06-10 15:22:18 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-06-10 15:22:18 +0000 |
commit | b972457783f6f992d8ee2fe392609fd4b0c5cf00 (patch) | |
tree | df8f2d9f75c999482e8ae2293ce3cd2fa7920937 /lib | |
parent | 91de80a5350b801b10323e65a6f3ee0f7dfb54f5 (diff) | |
download | external_llvm-b972457783f6f992d8ee2fe392609fd4b0c5cf00.zip external_llvm-b972457783f6f992d8ee2fe392609fd4b0c5cf00.tar.gz external_llvm-b972457783f6f992d8ee2fe392609fd4b0c5cf00.tar.bz2 |
Fix an out of bounds array access.
We were looking at Magic[5] without checking Length. Since this path would not
return unless Length >= 18 anyway, just move the >= 18 check up.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@183666 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Support/Path.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp index 5b34c5e..b6eeb14 100644 --- a/lib/Support/Path.cpp +++ b/lib/Support/Path.cpp @@ -58,11 +58,12 @@ sys::identifyFileType(const char *Magic, unsigned Length) { break; case '\177': - if (Magic[1] == 'E' && Magic[2] == 'L' && Magic[3] == 'F') { + if (Length >= 18 && Magic[1] == 'E' && Magic[2] == 'L' && + Magic[3] == 'F') { bool Data2MSB = Magic[5] == 2; unsigned high = Data2MSB ? 16 : 17; unsigned low = Data2MSB ? 17 : 16; - if (Length >= 18 && Magic[high] == 0) + if (Magic[high] == 0) switch (Magic[low]) { default: break; case 1: return ELF_Relocatable_FileType; |