diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-06-11 17:25:45 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-06-11 17:25:45 +0000 |
commit | 0179706213212cd35f43365ad912558ebe0e84b0 (patch) | |
tree | e7e6c25aadd61692b9f542ec668bd756dbb19261 /lib | |
parent | 9bd9f8e839de7e85f02a20f01fe4d0c129147f46 (diff) | |
download | external_llvm-0179706213212cd35f43365ad912558ebe0e84b0.zip external_llvm-0179706213212cd35f43365ad912558ebe0e84b0.tar.gz external_llvm-0179706213212cd35f43365ad912558ebe0e84b0.tar.bz2 |
Port r183666 to identify_magic.
It will be tested in the next commit which moves another user to identify_magic.
Original message:
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@183753 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Support/PathV2.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/Support/PathV2.cpp b/lib/Support/PathV2.cpp index 1546e07..9533e78 100644 --- a/lib/Support/PathV2.cpp +++ b/lib/Support/PathV2.cpp @@ -788,11 +788,12 @@ error_code has_magic(const Twine &path, const Twine &magic, bool &result) { break; case '\177': - if (Magic[1] == 'E' && Magic[2] == 'L' && Magic[3] == 'F') { + if (Magic.size() >= 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 (Magic.size() >= 18 && Magic[high] == 0) + if (Magic[high] == 0) switch (Magic[low]) { default: break; case 1: return file_magic::elf_relocatable; |