[llvm] r321166 - [TargetParser] Check size before accessing architecture version.
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 20 03:32:44 PST 2017
Author: fhahn
Date: Wed Dec 20 03:32:43 2017
New Revision: 321166
URL: http://llvm.org/viewvc/llvm-project?rev=321166&view=rev
Log:
[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
Modified:
llvm/trunk/lib/Support/TargetParser.cpp
llvm/trunk/unittests/Support/TargetParserTest.cpp
Modified: llvm/trunk/lib/Support/TargetParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/TargetParser.cpp?rev=321166&r1=321165&r2=321166&view=diff
==============================================================================
--- llvm/trunk/lib/Support/TargetParser.cpp (original)
+++ llvm/trunk/lib/Support/TargetParser.cpp Wed Dec 20 03:32:43 2017
@@ -537,7 +537,7 @@ StringRef llvm::AArch64::getDefaultCPU(S
}
unsigned llvm::AArch64::checkArchVersion(StringRef Arch) {
- if (Arch[0] == 'v' && std::isdigit(Arch[1]))
+ if (Arch.size() >= 2 && Arch[0] == 'v' && std::isdigit(Arch[1]))
return (Arch[1] - 48);
return 0;
}
@@ -633,7 +633,7 @@ StringRef llvm::ARM::getCanonicalArchNam
// Only match non-marketing names
if (offset != StringRef::npos) {
// Must start with 'vN'.
- if (A[0] != 'v' || !std::isdigit(A[1]))
+ if (A.size() >= 2 && (A[0] != 'v' || !std::isdigit(A[1])))
return Error;
// Can't have an extra 'eb'.
if (A.find("eb") != StringRef::npos)
Modified: llvm/trunk/unittests/Support/TargetParserTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/TargetParserTest.cpp?rev=321166&r1=321165&r2=321166&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/TargetParserTest.cpp (original)
+++ llvm/trunk/unittests/Support/TargetParserTest.cpp Wed Dec 20 03:32:43 2017
@@ -278,6 +278,12 @@ TEST(TargetParserTest, testARMCPU) {
"7-S"));
}
+TEST(TargetParserTest, testInvalidARMArch) {
+ auto InvalidArchStrings = {"armv", "armv99", "noarm"};
+ for (const char* InvalidArch : InvalidArchStrings)
+ EXPECT_EQ(ARM::parseArch(InvalidArch), ARM::ArchKind::INVALID);
+}
+
bool testARMArch(StringRef Arch, StringRef DefaultCPU, StringRef SubArch,
unsigned ArchAttr) {
ARM::ArchKind AK = ARM::parseArch(Arch);
More information about the llvm-commits
mailing list