[clang-tools-extra] [clang-tidy] Fix UB in SuspiciousIncludeCheck when IgnoredRegex is not set (PR #194521)
Harlen Batagelo via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 27 20:21:19 PDT 2026
https://github.com/hbatagelo created https://github.com/llvm/llvm-project/pull/194521
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.
>From 0d38415cabf1c81192ce8b8a89d1fd162955deb3 Mon Sep 17 00:00:00 2001
From: Harlen Batagelo <hbatagelo at gmail.com>
Date: Tue, 28 Apr 2026 00:13:58 -0300
Subject: [PATCH] Use empty string instead of default-constructed StringRef
when IgnoredRegex is not set
---
.../clang-tidy/bugprone/SuspiciousIncludeCheck.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
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(
More information about the cfe-commits
mailing list