summaryrefslogtreecommitdiffstats
path: root/gnu/llvm/lib/BinaryFormat/Magic.cpp
diff options
context:
space:
mode:
authorpatrick <patrick@openbsd.org>2018-04-06 14:26:03 +0000
committerpatrick <patrick@openbsd.org>2018-04-06 14:26:03 +0000
commitbdabc2f19ffb9e20600dad6e8a300842a7bda50e (patch)
treec50e7b2e5449b074651bb82a58517a8ebc4a8cf7 /gnu/llvm/lib/BinaryFormat/Magic.cpp
parentPrint a 'p' flag for file descriptors that were opened after pledge(2). (diff)
downloadwireguard-openbsd-bdabc2f19ffb9e20600dad6e8a300842a7bda50e.tar.xz
wireguard-openbsd-bdabc2f19ffb9e20600dad6e8a300842a7bda50e.zip
Import LLVM 6.0.1 release including clang, lld and lldb.
"where is the kaboom?" deraadt@
Diffstat (limited to 'gnu/llvm/lib/BinaryFormat/Magic.cpp')
-rw-r--r--gnu/llvm/lib/BinaryFormat/Magic.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/gnu/llvm/lib/BinaryFormat/Magic.cpp b/gnu/llvm/lib/BinaryFormat/Magic.cpp
index b19a07a9066..42546eaa732 100644
--- a/gnu/llvm/lib/BinaryFormat/Magic.cpp
+++ b/gnu/llvm/lib/BinaryFormat/Magic.cpp
@@ -182,11 +182,11 @@ file_magic llvm::identify_magic(StringRef Magic) {
break;
case 'M': // Possible MS-DOS stub on Windows PE file
- if (startswith(Magic, "MZ")) {
+ if (startswith(Magic, "MZ") && Magic.size() >= 0x3c + 4) {
uint32_t off = read32le(Magic.data() + 0x3c);
// PE/COFF file, either EXE or DLL.
- if (off < Magic.size() &&
- memcmp(Magic.data() + off, COFF::PEMagic, sizeof(COFF::PEMagic)) == 0)
+ if (Magic.substr(off).startswith(
+ StringRef(COFF::PEMagic, sizeof(COFF::PEMagic))))
return file_magic::pecoff_executable;
}
break;