https://github.com/bc-lee updated https://github.com/llvm/llvm-project/pull/68525
>From b272173acb8c2f92b5c5b7ebca4c00e4ac21037c Mon Sep 17 00:00:00 2001 From: Byoungchan Lee <byoungchan....@gmx.com> Date: Sun, 8 Oct 2023 21:47:05 +0900 Subject: [PATCH] [Clang][Frontend] Fix a crash when -Wdocumentation is used This commit resolves a crash issue in Clang's frontend caused while using the `-Wdocumentation` compiler flag. The flaw was due to the lack of necessary checks before the extraction of text between the comment and the declaration in the `ASTContext.cpp` file. Specifically, there was no verification to ensure that the second component of the declaration location's decomposition is not less than the comment's end offset. This could lead to an invalid length being passed to the `StringRef` constructor, triggering the crash. I have added a check to prevent this crash from occurring. Fixes #68524. --- clang/lib/AST/ASTContext.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index cdc3d62bca00873..7b4a4202921281c 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -344,6 +344,9 @@ RawComment *ASTContext::getRawCommentForDeclNoCacheImpl( if (Invalid) return nullptr; + if (DeclLocDecomp.second < CommentEndOffset) + return nullptr; + // Extract text between the comment and declaration. StringRef Text(Buffer + CommentEndOffset, DeclLocDecomp.second - CommentEndOffset); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits