[llvm] [MC][AsmLexer] 'LexToken()': fix potential buffer overflow. (PR #105312)

via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 20 12:56:20 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mc

Author: None (PavelKopyl)

<details>
<summary>Changes</summary>

When the 'CurPtr' points to the 'EOF', calling either 'isAtStartOfComment', or 'isAtStatementSeparator' leads to dereferencing of 'CurBuf.end()'.
Usually this issue is hidden, as the AsmParser receives a source code via MemoryBuffer object with the null-terminating symbol, but the null-terminator is not required for AsmParser logic.

---
Full diff: https://github.com/llvm/llvm-project/pull/105312.diff


1 Files Affected:

- (modified) llvm/lib/MC/MCParser/AsmLexer.cpp (+2-2) 


``````````diff
diff --git a/llvm/lib/MC/MCParser/AsmLexer.cpp b/llvm/lib/MC/MCParser/AsmLexer.cpp
index 778ca340e12489..517e99c4a2915d 100644
--- a/llvm/lib/MC/MCParser/AsmLexer.cpp
+++ b/llvm/lib/MC/MCParser/AsmLexer.cpp
@@ -752,10 +752,10 @@ AsmToken AsmLexer::LexToken() {
       return LexLineComment();
   }
 
-  if (isAtStartOfComment(TokStart))
+  if (CurChar != EOF && isAtStartOfComment(TokStart))
     return LexLineComment();
 
-  if (isAtStatementSeparator(TokStart)) {
+  if (CurChar != EOF && isAtStatementSeparator(TokStart)) {
     CurPtr += strlen(MAI.getSeparatorString()) - 1;
     IsAtStartOfLine = true;
     IsAtStartOfStatement = true;

``````````

</details>


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


More information about the llvm-commits mailing list