-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[clang][lex] Fix lexing malformed pragma within include directive #138165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clang Author: Stefan (sweiglbosker) Changesfixes: #138094 Full diff: https://github.com/llvm/llvm-project/pull/138165.diff 1 Files Affected:
diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp
index 5b6a29bdad910..607e7b6a7dceb 100644
--- a/clang/lib/Lex/Pragma.cpp
+++ b/clang/lib/Lex/Pragma.cpp
@@ -220,11 +220,12 @@ void Preprocessor::Handle_Pragma(Token &Tok) {
if (!tok::isStringLiteral(Tok.getKind())) {
Diag(PragmaLoc, diag::err__Pragma_malformed);
// Skip bad tokens, and the ')', if present.
- if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::eof))
+ if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::eof) && Tok.isNot(tok::eod))
Lex(Tok);
while (Tok.isNot(tok::r_paren) &&
!Tok.isAtStartOfLine() &&
- Tok.isNot(tok::eof))
+ Tok.isNot(tok::eof) &&
+ Tok.isNot(tok::eod))
Lex(Tok);
if (Tok.is(tok::r_paren))
Lex(Tok);
|
You can test this locally with the following command:git-clang-format --diff HEAD~1 HEAD --extensions cpp -- clang/lib/Lex/Pragma.cpp View the diff from clang-format here.diff --git a/clang/lib/Lex/Pragma.cpp b/clang/lib/Lex/Pragma.cpp
index 607e7b6a7..ea7eda0d0 100644
--- a/clang/lib/Lex/Pragma.cpp
+++ b/clang/lib/Lex/Pragma.cpp
@@ -222,10 +222,8 @@ void Preprocessor::Handle_Pragma(Token &Tok) {
// Skip bad tokens, and the ')', if present.
if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::eof) && Tok.isNot(tok::eod))
Lex(Tok);
- while (Tok.isNot(tok::r_paren) &&
- !Tok.isAtStartOfLine() &&
- Tok.isNot(tok::eof) &&
- Tok.isNot(tok::eod))
+ while (Tok.isNot(tok::r_paren) && !Tok.isAtStartOfLine() &&
+ Tok.isNot(tok::eof) && Tok.isNot(tok::eod))
Lex(Tok);
if (Tok.is(tok::r_paren))
Lex(Tok);
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the fix, this needs a test and release note.
Release notes for clang are in clang/docs/ReleaseNotes.rst
.
I am not sure what the right file for testing is though @AaronBallman
Thanks for the fix! Given the nature of the issue, I would probably introduce a new test file rather than modify an existing one. But I think it should live in |
429b48c
to
2865b67
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally LGTM, though a few suggested changes.
Done |
@sweiglbosker Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
…vm#138165) this patch fixes a crash triggered by lexing past eof when emitting a diagnostic for a malformed `_Pragma` directive within an `include` directive. Fixed by by preventing the lexer from eating a `tok::eod`. Fixes llvm#138094
…vm#138165) this patch fixes a crash triggered by lexing past eof when emitting a diagnostic for a malformed `_Pragma` directive within an `include` directive. Fixed by by preventing the lexer from eating a `tok::eod`. Fixes llvm#138094
…vm#138165) this patch fixes a crash triggered by lexing past eof when emitting a diagnostic for a malformed `_Pragma` directive within an `include` directive. Fixed by by preventing the lexer from eating a `tok::eod`. Fixes llvm#138094
…vm#138165) this patch fixes a crash triggered by lexing past eof when emitting a diagnostic for a malformed `_Pragma` directive within an `include` directive. Fixed by by preventing the lexer from eating a `tok::eod`. Fixes llvm#138094
fixes: #138094
this patch fixes a crash triggered by lexing past eof when emitting a diagnostic for a malformed
_Pragma
directive within aninclude
directive.Fixed by by preventing the lexer from eating a
tok::eod
.