Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 196340c

Browse files
committed
[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
1 parent b0b8cde commit 196340c

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

lib/Object/ELFObjectFile.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,15 @@ ObjectFile::createELFObjectFile(MemoryBufferRef Obj) {
3939
R.reset(new ELFObjectFile<ELFType<support::big, false>>(Obj, EC));
4040
else
4141
return object_error::parse_failed;
42-
} else {
43-
assert(Ident.first == ELF::ELFCLASS64);
42+
} else if (Ident.first == ELF::ELFCLASS64) {
4443
if (Ident.second == ELF::ELFDATA2LSB)
4544
R.reset(new ELFObjectFile<ELFType<support::little, true>>(Obj, EC));
4645
else if (Ident.second == ELF::ELFDATA2MSB)
4746
R.reset(new ELFObjectFile<ELFType<support::big, true>>(Obj, EC));
4847
else
4948
return object_error::parse_failed;
49+
} else {
50+
return object_error::parse_failed;
5051
}
5152

5253
if (EC)

test/DebugInfo/Inputs/invalid.elf.3

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ELF�L�'ELFB

test/DebugInfo/dwarfdump-invalid.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

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

0 commit comments

Comments
 (0)