mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 11:13:28 +01:00
Fix buffer overflow.
We were reading past the end of the buffer. llvm-svn: 316143
This commit is contained in:
parent
73a2505e62
commit
4d7e642f7d
@ -185,7 +185,7 @@ file_magic llvm::identify_magic(StringRef Magic) {
|
||||
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() &&
|
||||
if (off + sizeof(COFF::PEMagic) <= Magic.size() &&
|
||||
memcmp(Magic.data() + off, COFF::PEMagic, sizeof(COFF::PEMagic)) == 0)
|
||||
return file_magic::pecoff_executable;
|
||||
}
|
||||
|
BIN
test/Object/Inputs/invalid-coff-header-too-small
Normal file
BIN
test/Object/Inputs/invalid-coff-header-too-small
Normal file
Binary file not shown.
@ -86,3 +86,6 @@ INVALID-REL-SYM: invalid section offset
|
||||
|
||||
RUN: not llvm-readobj -r %p/Inputs/invalid-buffer.elf 2>&1 | FileCheck --check-prefix=INVALID-BUFFER %s
|
||||
INVALID-BUFFER: Invalid buffer
|
||||
|
||||
RUN: not llvm-readobj %p/Inputs/invalid-coff-header-too-small 2>&1 | FileCheck --check-prefix=COFF-HEADER %s
|
||||
COFF-HEADER: The file was not recognized as a valid object file
|
||||
|
Loading…
Reference in New Issue
Block a user