llvm.org GIT mirror llvm / a392df9
[TargetParser] Check size before accessing architecture version. Summary: This fixes a crash when invalid -march options like `armv` are provided. Based on a patch by Will Lovett. Reviewers: rengolin, samparker, mcrosier Reviewed By: samparker Subscribers: aemerson, kristof.beyls, llvm-commits Differential Revision: https://reviews.llvm.org/D41429 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@321166 91177308-0d34-0410-b5e6-96231b3b80d8 Florian Hahn 2 years ago
2 changed file(s) with 8 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
536536 }
537537
538538 unsigned llvm::AArch64::checkArchVersion(StringRef Arch) {
539 if (Arch[0] == 'v' && std::isdigit(Arch[1]))
539 if (Arch.size() >= 2 && Arch[0] == 'v' && std::isdigit(Arch[1]))
540540 return (Arch[1] - 48);
541541 return 0;
542542 }
632632 // Only match non-marketing names
633633 if (offset != StringRef::npos) {
634634 // Must start with 'vN'.
635 if (A[0] != 'v' || !std::isdigit(A[1]))
635 if (A.size() >= 2 && (A[0] != 'v' || !std::isdigit(A[1])))
636636 return Error;
637637 // Can't have an extra 'eb'.
638638 if (A.find("eb") != StringRef::npos)
277277 "7-S"));
278278 }
279279
280 TEST(TargetParserTest, testInvalidARMArch) {
281 auto InvalidArchStrings = {"armv", "armv99", "noarm"};
282 for (const char* InvalidArch : InvalidArchStrings)
283 EXPECT_EQ(ARM::parseArch(InvalidArch), ARM::ArchKind::INVALID);
284 }
285
280286 bool testARMArch(StringRef Arch, StringRef DefaultCPU, StringRef SubArch,
281287 unsigned ArchAttr) {
282288 ARM::ArchKind AK = ARM::parseArch(Arch);