[llvm] [MCParser] AsmLexer invalid read fix. (PR #154972)
Szymon Piotr Milczek via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 22 08:50:32 PDT 2025
https://github.com/smilczek created https://github.com/llvm/llvm-project/pull/154972
AsmLexer::LexToken() switch statement contains a loop that's meant to
skip past indentation. This loop however doesn't check if CurPtr is at
the end of CurBuf before dereferencing. This can cause an issue with
invalid reads.
This commit adds a condition `CurPtr != CurBuf.end()` to ensure no
invalid reads will be made.
>From 86367d22ef0761108a1592896f02b4adbf337d94 Mon Sep 17 00:00:00 2001
From: "Milczek, Szymon" <szymon.milczek at intel.com>
Date: Fri, 22 Aug 2025 17:44:51 +0200
Subject: [PATCH] [MCParser] AsmLexer invalid read fix.
AsmLexer::LexToken() switch statement contains a loop that's meant to
skip past indentation. This loop however doesn't check if CurPtr is at
the end of CurBuf before dereferencing. This can cause an issue with
invalid reads.
This commit adds a condition `CurPtr != CurBuf.end()` to ensure no
invalid reads will be made.
---
llvm/lib/MC/MCParser/AsmLexer.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/MC/MCParser/AsmLexer.cpp b/llvm/lib/MC/MCParser/AsmLexer.cpp
index 968ccf776440b..e70eae7720258 100644
--- a/llvm/lib/MC/MCParser/AsmLexer.cpp
+++ b/llvm/lib/MC/MCParser/AsmLexer.cpp
@@ -878,7 +878,7 @@ AsmToken AsmLexer::LexToken() {
case ' ':
case '\t':
IsAtStartOfStatement = OldIsAtStartOfStatement;
- while (*CurPtr == ' ' || *CurPtr == '\t')
+ while (CurPtr != CurBuf.end() && (*CurPtr == ' ' || *CurPtr == '\t'))
CurPtr++;
if (SkipSpace)
return LexToken(); // Ignore whitespace.
More information about the llvm-commits
mailing list