[PATCH] D41429: [TargetParser] Check size before accessing architecture version.
Florian Hahn via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 20 01:33:30 PST 2017
fhahn created this revision.
fhahn added reviewers: rengolin, samparker, mcrosier.
Herald added subscribers: kristof.beyls, aemerson.
This fixes a crash when invalid -march options like `armv` are provided.
Based on a patch by Will Lovett.
https://reviews.llvm.org/D41429
Files:
lib/Support/TargetParser.cpp
unittests/Support/TargetParserTest.cpp
Index: unittests/Support/TargetParserTest.cpp
===================================================================
--- unittests/Support/TargetParserTest.cpp
+++ unittests/Support/TargetParserTest.cpp
@@ -278,6 +278,12 @@
"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);
Index: lib/Support/TargetParser.cpp
===================================================================
--- lib/Support/TargetParser.cpp
+++ lib/Support/TargetParser.cpp
@@ -537,7 +537,7 @@
}
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 @@
// 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)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41429.127668.patch
Type: text/x-patch
Size: 1395 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171220/d7c42178/attachment.bin>
More information about the llvm-commits
mailing list