[clang] [clang] Fix a possible out-of-bounds read (PR #80023)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 2 01:12:53 PST 2024


================
@@ -1251,7 +1251,7 @@ highlightLines(StringRef FileData, unsigned StartLineNumber,
     unsigned LineLength = 0;
     for (unsigned I = 0; I <= Spelling.size(); ++I) {
       // This line is done.
-      if (isVerticalWhitespace(Spelling[I]) || I == Spelling.size()) {
+      if (I == Spelling.size() || isVerticalWhitespace(Spelling.at(I))) {
----------------
tbaederr wrote:

Well it would've been caught earlier if it had been using `at()` in the first place.

> We have a repro? ( I don't insist on having one to land that though)

Even though I have assertions and sanitizers (but not msan) enabled locally, the `Spelling[I]` did not crash for me or cause anything else in the `I == Spelling.size()` case.


https://github.com/llvm/llvm-project/pull/80023


More information about the cfe-commits mailing list