Skip to content

Conversation

smilczek
Copy link
Contributor

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.

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.
@llvmbot llvmbot added the llvm:mc Machine (object) code label Aug 22, 2025
@smilczek smilczek changed the title [MCParser] AsmLexer invalid read fix. [LLVM] AsmLexer invalid read fix. Aug 22, 2025
@smilczek
Copy link
Contributor Author

@MaskRay

@MaskRay
Copy link
Member

MaskRay commented Aug 22, 2025

Need a llvm/test/MC/AsmParser test to confirm we actually have the out-of-bounds error and fix it.

@nikic nikic changed the title [LLVM] AsmLexer invalid read fix. [MC] AsmLexer invalid read fix. Aug 22, 2025
@smilczek
Copy link
Contributor Author

Note self: need to create a binary file which will end with 0x20 (space character) and another file that will contain the commands to run the test. Possibly put assert(CurPtr <= CurBuf.end()) in getNextChar() to force a failure in case of invalid read.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:mc Machine (object) code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants