[Object, ELF] Don't assert on invalid magic in createELFObjectFile.

Instead, return a proper error code from factory.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@239116 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alexey Samsonov 2015-06-04 23:14:43 +00:00
parent b0b8cde9d4
commit 196340cc6c
3 changed files with 5 additions and 2 deletions

View File

@ -39,14 +39,15 @@ ObjectFile::createELFObjectFile(MemoryBufferRef Obj) {
R.reset(new ELFObjectFile<ELFType<support::big, false>>(Obj, EC));
else
return object_error::parse_failed;
} else {
assert(Ident.first == ELF::ELFCLASS64);
} else if (Ident.first == ELF::ELFCLASS64) {
if (Ident.second == ELF::ELFDATA2LSB)
R.reset(new ELFObjectFile<ELFType<support::little, true>>(Obj, EC));
else if (Ident.second == ELF::ELFDATA2MSB)
R.reset(new ELFObjectFile<ELFType<support::big, true>>(Obj, EC));
else
return object_error::parse_failed;
} else {
return object_error::parse_failed;
}
if (EC)

View File

@ -0,0 +1 @@
ELFLþ'ELFB

View File

@ -2,4 +2,5 @@
RUN: llvm-dwarfdump %p/Inputs/invalid.elf 2>&1 | FileCheck %s --check-prefix=INVALID-ELF
RUN: llvm-dwarfdump %p/Inputs/invalid.elf.2 2>&1 | FileCheck %s --check-prefix=INVALID-ELF
RUN: llvm-dwarfdump %p/Inputs/invalid.elf.3 2>&1 | FileCheck %s --check-prefix=INVALID-ELF
INVALID-ELF: Invalid data was encountered while parsing the file