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 | 548e9d48346a28256c92e123d530377e7884b519 (patch) | |
tree | 54dc8ce2a16989b6c4b069f34baf9e330d664cb0 /llvm/lib/Support/Path.cpp | |
parent | 693b4750d11fa904d8da26ff5d1b4d22947f64b1 (diff) | |
download | bcm5719-llvm-548e9d48346a28256c92e123d530377e7884b519.tar.gz bcm5719-llvm-548e9d48346a28256c92e123d530377e7884b519.zip |
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.
llvm-svn: 183666
Diffstat (limited to 'llvm/lib/Support/Path.cpp')
-rw-r--r-- | llvm/lib/Support/Path.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp index 5b34c5eab68..b6eeb1484cf 100644 --- a/llvm/lib/Support/Path.cpp +++ b/llvm/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; |