Skip to content

Commit eabf1d3

Browse files
committed
[RISCV] check pointer before dereference
Encountered ASAN crash and found it dereference without check pointer. Reviewed By: kito-cheng, eklepilkina Differential Revision: https://reviews.llvm.org/D151716
1 parent 6ed152a commit eabf1d3

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

llvm/lib/Support/RISCVISAInfo.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -699,9 +699,10 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
699699

700700
auto StdExtsItr = StdExts.begin();
701701
auto StdExtsEnd = StdExts.end();
702-
auto GoToNextExt = [](StringRef::iterator &I, unsigned ConsumeLength) {
702+
auto GoToNextExt = [](StringRef::iterator &I, unsigned ConsumeLength,
703+
StringRef::iterator E) {
703704
I += 1 + ConsumeLength;
704-
if (*I == '_')
705+
if (I != E && *I == '_')
705706
++I;
706707
};
707708
for (auto I = Exts.begin(), E = Exts.end(); I != E;) {
@@ -737,7 +738,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
737738
ExperimentalExtensionVersionCheck)) {
738739
if (IgnoreUnknown) {
739740
consumeError(std::move(E));
740-
GoToNextExt(I, ConsumeLength);
741+
GoToNextExt(I, ConsumeLength, Exts.end());
741742
continue;
742743
}
743744
return std::move(E);
@@ -747,7 +748,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
747748
// Currently LLVM supports only "mafdcvh".
748749
if (!isSupportedExtension(StringRef(&C, 1))) {
749750
if (IgnoreUnknown) {
750-
GoToNextExt(I, ConsumeLength);
751+
GoToNextExt(I, ConsumeLength, Exts.end());
751752
continue;
752753
}
753754
return createStringError(errc::invalid_argument,
@@ -758,7 +759,7 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
758759

759760
// Consume full extension name and version, including any optional '_'
760761
// between this extension and the next
761-
GoToNextExt(I, ConsumeLength);
762+
GoToNextExt(I, ConsumeLength, Exts.end());
762763
}
763764

764765
// Handle other types of extensions other than the standard

0 commit comments

Comments
 (0)