Index: lib/Support/ARMAttributeParser.cpp =================================================================== --- lib/Support/ARMAttributeParser.cpp +++ lib/Support/ARMAttributeParser.cpp @@ -709,6 +709,12 @@ SW->indent(); } + if (SectionLength == 0 || (SectionLength + Offset) > Section.size()) { + errs() << "invalid subsection length " << SectionLength << " at offset " + << Offset << "\n"; + return; + } + ParseSubsection(Section.data() + Offset, SectionLength); Offset = Offset + SectionLength; Index: tools/lld/test/ELF/bad-arm-attributes.test =================================================================== --- tools/lld/test/ELF/bad-arm-attributes.test +++ tools/lld/test/ELF/bad-arm-attributes.test @@ -0,0 +1,19 @@ +# RUN: yaml2obj %s -o %t.o +# RUN: ld.lld %t.o 2>&1 | FileCheck %s + +# CHECK: invalid subsection length 0 at offset 1 + +!ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM +Sections: + - Name: .ARM.attributes + Type: SHT_ARM_ATTRIBUTES + Flags: [ SHF_ALLOC ] + Content: "00000000000000" + Address: 0x1000 + AddressAlign: 0x8 + Index: tools/lld/test/ELF/bad-arm-attributes2.test =================================================================== --- tools/lld/test/ELF/bad-arm-attributes2.test +++ tools/lld/test/ELF/bad-arm-attributes2.test @@ -0,0 +1,19 @@ +# RUN: yaml2obj %s -o %t.o +# RUN: ld.lld %t.o 2>&1 | FileCheck %s + +# CHECK: invalid subsection length 65535 at offset 1 + +!ELF +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_ARM +Sections: + - Name: .ARM.attributes + Type: SHT_ARM_ATTRIBUTES + Flags: [ SHF_ALLOC ] + Content: "00FFFF00000000" + Address: 0x1000 + AddressAlign: 0x8 +