[llvm] [MC] AsmLexer invalid read fix. (PR #154972)

Szymon Piotr Milczek via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 15 11:20:46 PDT 2025


================
@@ -120,6 +120,11 @@ AsmLexer::AsmLexer(const MCAsmInfo &MAI) : MAI(MAI) {
 
 void AsmLexer::setBuffer(StringRef Buf, const char *ptr,
                          bool EndStatementAtEOF) {
+  // Null terminator must be part of the actual buffer. It must reside at
+  // `Buf.end()`. It must be safe to dereference `Buf.end()`.
+  assert(*Buf.end() == '\0' &&
+         "Buffer provided to AsmLexer lacks null terminator.");
+
----------------
smilczek wrote:

To additionally clarify, since I didn't mention it above, if a buffer IS null-terminated, however the null terminator resides at `CurBuf.end() - 1` (which doesn't seem unreasonable), the problem with invalid reads will appear.

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


More information about the llvm-commits mailing list