Skip to content

[clang-tidy] Fix buffer overflow in compareHeaders #87213

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

vitalybuka
Copy link
Collaborator

@vitalybuka vitalybuka commented Apr 1, 2024

RHS can be shorter than LHS.

Reported by asan after #83440.

Created using spr 1.3.4
@llvmbot
Copy link
Member

llvmbot commented Apr 1, 2024

@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clang-tidy

Author: Vitaly Buka (vitalybuka)

Changes

RHS can be shorter than LHS.

Reported by asan after #83440.


Full diff: https://github.com/llvm/llvm-project/pull/87213.diff

1 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp (+1-1)
diff --git a/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp b/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp
index b6d9c50d0b109c..a44720c47eca2d 100644
--- a/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp
+++ b/clang-tools-extra/clang-tidy/utils/IncludeSorter.cpp
@@ -108,7 +108,7 @@ int compareHeaders(StringRef LHS, StringRef RHS,
                    IncludeSorter::IncludeStyle Style) {
   if (Style == IncludeSorter::IncludeStyle::IS_Google_ObjC) {
     const std::pair<const char *, const char *> &Mismatch =
-        std::mismatch(LHS.begin(), LHS.end(), RHS.begin());
+        std::mismatch(LHS.begin(), LHS.end(), RHS.begin(), RHS.end());
     if ((Mismatch.first != LHS.end()) && (Mismatch.second != RHS.end())) {
       if ((*Mismatch.first == '.') && (*Mismatch.second == '+')) {
         return -1;

@vitalybuka vitalybuka merged commit a21e0ba into main Apr 1, 2024
@vitalybuka vitalybuka deleted the users/vitalybuka/spr/clang-tidy-fix-buffer-overflow-in-compareheaders branch April 1, 2024 04:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants