[clang-tools-extra] 7f5abb6 - [clangd] Fix a use-after-free
Kadir Cetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 25 10:26:44 PDT 2021
Author: Kadir Cetinkaya
Date: 2021-03-25T18:26:17+01:00
New Revision: 7f5abb63733238b89cf5d47116b2af68cda2af4e
URL: https://github.com/llvm/llvm-project/commit/7f5abb63733238b89cf5d47116b2af68cda2af4e
DIFF: https://github.com/llvm/llvm-project/commit/7f5abb63733238b89cf5d47116b2af68cda2af4e.diff
LOG: [clangd] Fix a use-after-free
Clangd was storing reference to a possibly-dead string in compiled
config. This patch fixes the issue by copying suppression strings from
fragments into compiled Config.
Fixes https://github.com/clangd/clangd/issues/724.
Differential Revision: https://reviews.llvm.org/D99326
Added:
Modified:
clang-tools-extra/clangd/ConfigCompile.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/ConfigCompile.cpp b/clang-tools-extra/clangd/ConfigCompile.cpp
index 9aed3c4679f5e..8f402ae061535 100644
--- a/clang-tools-extra/clangd/ConfigCompile.cpp
+++ b/clang-tools-extra/clangd/ConfigCompile.cpp
@@ -371,7 +371,7 @@ struct FragmentCompiler {
}
void compile(Fragment::DiagnosticsBlock &&F) {
- std::vector<llvm::StringRef> Normalized;
+ std::vector<std::string> Normalized;
for (const auto &Suppressed : F.Suppress) {
if (*Suppressed == "*") {
Out.Apply.push_back([&](const Params &, Config &C) {
@@ -380,15 +380,16 @@ struct FragmentCompiler {
});
return;
}
- Normalized.push_back(normalizeSuppressedCode(*Suppressed));
+ Normalized.push_back(normalizeSuppressedCode(*Suppressed).str());
}
if (!Normalized.empty())
- Out.Apply.push_back([Normalized](const Params &, Config &C) {
- if (C.Diagnostics.SuppressAll)
- return;
- for (llvm::StringRef N : Normalized)
- C.Diagnostics.Suppress.insert(N);
- });
+ Out.Apply.push_back(
+ [Normalized(std::move(Normalized))](const Params &, Config &C) {
+ if (C.Diagnostics.SuppressAll)
+ return;
+ for (llvm::StringRef N : Normalized)
+ C.Diagnostics.Suppress.insert(N);
+ });
compile(std::move(F.ClangTidy));
}
More information about the cfe-commits
mailing list