summaryrefslogtreecommitdiff
path: root/clang-tools-extra/clangd/ConfigCompile.cpp
diff options
context:
space:
mode:
authorSam McCall <sam.mccall@gmail.com>2021-04-15 12:52:58 +0200
committerSam McCall <sam.mccall@gmail.com>2021-04-15 14:51:23 +0200
commitecf93a716c9ecf2e38898547df90323e239a623c (patch)
tree9acdd3dea15baf153ec7f47b11a8be131229a243 /clang-tools-extra/clangd/ConfigCompile.cpp
parent49cbf4cd85a9ae6b53947fb8cf39ccfb56becc57 (diff)
downloadllvm-ecf93a716c9ecf2e38898547df90323e239a623c.tar.gz
[clangd] Only allow remote index to be enabled from user config.
Differential Revision: https://reviews.llvm.org/D100542
Diffstat (limited to 'clang-tools-extra/clangd/ConfigCompile.cpp')
-rw-r--r--clang-tools-extra/clangd/ConfigCompile.cpp13
1 files changed, 11 insertions, 2 deletions
diff --git a/clang-tools-extra/clangd/ConfigCompile.cpp b/clang-tools-extra/clangd/ConfigCompile.cpp
index a5745727dca7..31beb6ac10cb 100644
--- a/clang-tools-extra/clangd/ConfigCompile.cpp
+++ b/clang-tools-extra/clangd/ConfigCompile.cpp
@@ -101,6 +101,7 @@ struct FragmentCompiler {
llvm::SourceMgr *SourceMgr;
// Normalized Fragment::SourceInfo::Directory.
std::string FragmentDirectory;
+ bool Trusted = false;
llvm::Optional<llvm::Regex>
compileRegex(const Located<std::string> &Text,
@@ -183,6 +184,7 @@ struct FragmentCompiler {
}
void compile(Fragment &&F) {
+ Trusted = F.Source.Trusted;
if (!F.Source.Directory.empty()) {
FragmentDirectory = llvm::sys::path::convert_to_slash(F.Source.Directory);
if (FragmentDirectory.back() != '/')
@@ -320,6 +322,13 @@ struct FragmentCompiler {
void compile(Fragment::IndexBlock::ExternalBlock &&External,
llvm::SMRange BlockRange) {
+ if (External.Server && !Trusted) {
+ diag(Error,
+ "Remote index may not be specified by untrusted configuration. "
+ "Copy this into user config to use it.",
+ External.Server->Range);
+ return;
+ }
#ifndef CLANGD_ENABLE_REMOTE
if (External.Server) {
elog("Clangd isn't compiled with remote index support, ignoring Server: "
@@ -510,8 +519,8 @@ CompiledFragment Fragment::compile(DiagnosticCallback D) && {
trace::Span Tracer("ConfigCompile");
SPAN_ATTACH(Tracer, "ConfigFile", ConfigFile);
auto Result = std::make_shared<CompiledFragmentImpl>();
- vlog("Config fragment: compiling {0}:{1} -> {2}", ConfigFile, LineCol.first,
- Result.get());
+ vlog("Config fragment: compiling {0}:{1} -> {2} (trusted={3})", ConfigFile,
+ LineCol.first, Result.get(), Source.Trusted);
FragmentCompiler{*Result, D, Source.Manager.get()}.compile(std::move(*this));
// Return as cheaply-copyable wrapper.