[clang-tools-extra] [clang-tidy] Fix UB in SuspiciousIncludeCheck when IgnoredRegex is not set (PR #194521)

via cfe-commits cfe-commits at lists.llvm.org
Mon Apr 27 20:22:14 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

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

Author: Harlen Batagelo (hbatagelo)

<details>
<summary>Changes</summary>

When the "IgnoredRegex" option is not set, `IgnoredRegexString` is default-constructed, i.e. initialized with a null data pointer. This is passed to `llvm_regcomp` as the pattern argument, causing a nullptr+0 UB in regcomp.c:327 (caught by UBSan). Fix by initializing `IgnoredRegexString` with an empty string literal instead.

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


1 Files Affected:

- (modified) clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp (+1-1) 


``````````diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp
index d90e5dae650c7..38ee6595bbbbe 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SuspiciousIncludeCheck.cpp
@@ -39,7 +39,7 @@ class SuspiciousIncludePPCallbacks : public PPCallbacks {
 SuspiciousIncludeCheck::SuspiciousIncludeCheck(StringRef Name,
                                                ClangTidyContext *Context)
     : ClangTidyCheck(Name, Context),
-      IgnoredRegexString(Options.get("IgnoredRegex").value_or(StringRef{})),
+      IgnoredRegexString(Options.get("IgnoredRegex").value_or("")),
       IgnoredRegex(IgnoredRegexString) {}
 
 void SuspiciousIncludeCheck::registerPPCallbacks(

``````````

</details>


https://github.com/llvm/llvm-project/pull/194521


More information about the cfe-commits mailing list