diff options
author | Alex Lorenz <arphaman@gmail.com> | 2021-12-20 12:26:50 -0800 |
---|---|---|
committer | Alex Lorenz <arphaman@gmail.com> | 2022-02-02 11:16:11 -0800 |
commit | 979d0ee8ab30a175220af3b39a6df7d56de9d2c8 (patch) | |
tree | 4459753a3ce9aa911ed306c323736f3d84bbb054 /clang/lib/Frontend/PrintPreprocessedOutput.cpp | |
parent | aee705661fe8c2ecbf0e1766ee93dbad286a6b8c (diff) | |
download | llvm-979d0ee8ab30a175220af3b39a6df7d56de9d2c8.zip llvm-979d0ee8ab30a175220af3b39a6df7d56de9d2c8.tar.gz llvm-979d0ee8ab30a175220af3b39a6df7d56de9d2c8.tar.bz2 |
[clang] fix out of bounds access in an empty string when lexing a _Pragma with missing string token
The lexer can attempt to lex a _Pragma and crash with an out of bounds string access when it's
lexing a _Pragma whose string token is an invalid buffer, e.g. when a module header file from which the macro
expansion for that token was deleted from the file system.
Differential Revision: https://reviews.llvm.org/D116052
Diffstat (limited to 'clang/lib/Frontend/PrintPreprocessedOutput.cpp')
-rw-r--r-- | clang/lib/Frontend/PrintPreprocessedOutput.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp index 1d0022b..e2fc862 100644 --- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp +++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp @@ -189,7 +189,8 @@ public: bool MoveToLine(const Token &Tok, bool RequireStartOfLine) { PresumedLoc PLoc = SM.getPresumedLoc(Tok.getLocation()); unsigned TargetLine = PLoc.isValid() ? PLoc.getLine() : CurLine; - bool IsFirstInFile = Tok.isAtStartOfLine() && PLoc.getLine() == 1; + bool IsFirstInFile = + Tok.isAtStartOfLine() && PLoc.isValid() && PLoc.getLine() == 1; return MoveToLine(TargetLine, RequireStartOfLine) || IsFirstInFile; } |