summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Path.cpp
diff options
context:
space:
mode:
authorKevin Enderby <enderby@apple.com>2016-01-26 23:43:37 +0000
committerKevin Enderby <enderby@apple.com>2016-01-26 23:43:37 +0000
commit87c85b7e23f3d87b0c8a8826e3ebc867fca7e7ae (patch)
treefcc57d6c6144e54af650041845b208933c5e65b1 /llvm/lib/Support/Path.cpp
parent8e785a4ec08cf7119b9e50688b2baa9123fd4ae8 (diff)
downloadbcm5719-llvm-87c85b7e23f3d87b0c8a8826e3ebc867fca7e7ae.tar.gz
bcm5719-llvm-87c85b7e23f3d87b0c8a8826e3ebc867fca7e7ae.zip
Fix identify_magic() to check that a file that starts with MH_MAGIC is
at least as big as the mach header to be identified as a Mach-O file and make sure smaller files are not identified as a Mach-O files but as unknown files. Also fix identify_magic() so it looks at all 4 bytes of the filetype field when determining the type of the Mach-O file. Then fix the macho-invalid-header test case to check that it is an unknown file and make sure it does not get the error for object_error::parse_failed. And also update the unit tests. llvm-svn: 258883
Diffstat (limited to 'llvm/lib/Support/Path.cpp')
-rw-r--r--llvm/lib/Support/Path.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp
index 4952f59fc24..875bf75b1f0 100644
--- a/llvm/lib/Support/Path.cpp
+++ b/llvm/lib/Support/Path.cpp
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Support/COFF.h"
+#include "llvm/Support/MachO.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/Errc.h"
#include "llvm/Support/ErrorHandling.h"
@@ -1040,12 +1041,24 @@ file_magic identify_magic(StringRef Magic) {
Magic[2] == char(0xFA) &&
(Magic[3] == char(0xCE) || Magic[3] == char(0xCF))) {
/* Native endian */
- if (Magic.size() >= 16) type = Magic[14] << 8 | Magic[15];
+ size_t MinSize;
+ if (Magic[3] == char(0xCE))
+ MinSize = sizeof(MachO::mach_header);
+ else
+ MinSize = sizeof(MachO::mach_header_64);
+ if (Magic.size() >= MinSize)
+ type = Magic[12] << 24 | Magic[13] << 12 | Magic[14] << 8 | Magic[15];
} else if ((Magic[0] == char(0xCE) || Magic[0] == char(0xCF)) &&
Magic[1] == char(0xFA) && Magic[2] == char(0xED) &&
Magic[3] == char(0xFE)) {
/* Reverse endian */
- if (Magic.size() >= 14) type = Magic[13] << 8 | Magic[12];
+ size_t MinSize;
+ if (Magic[0] == char(0xCE))
+ MinSize = sizeof(MachO::mach_header);
+ else
+ MinSize = sizeof(MachO::mach_header_64);
+ if (Magic.size() >= MinSize)
+ type = Magic[15] << 24 | Magic[14] << 12 |Magic[13] << 8 | Magic[12];
}
switch (type) {
default: break;
OpenPOWER on IntegriCloud