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.s =================================================================== --- tools/lld/test/ELF/bad-arm-attributes.s +++ tools/lld/test/ELF/bad-arm-attributes.s @@ -0,0 +1,7 @@ +# RUN: llvm-mc -filetype=obj -triple=arm-unknown-linux %s -o %t +# RUN: ld.lld %t -o %tout 2>&1 | FileCheck %s + +# CHECK: invalid subsection length 0 at offset 1 + +.section .ARM.attributes,"a",%0x70000003 + .quad 0 Index: tools/lld/test/ELF/bad-arm-attributes2.s =================================================================== --- tools/lld/test/ELF/bad-arm-attributes2.s +++ tools/lld/test/ELF/bad-arm-attributes2.s @@ -0,0 +1,7 @@ +# RUN: llvm-mc -filetype=obj -triple=arm-unknown-linux %s -o %t +# RUN: ld.lld %t -o %tout 2>&1 | FileCheck %s + +# CHECK: invalid subsection length 4294967295 at offset 1 + +.section .ARM.attributes,"a",%0x70000003 + .byte 0, 0xFF, 0xFF, 0xFF, 0xFF