From 7b7cded1cc3ec7283cd648343150faf614f06468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 18 Aug 2020 11:41:35 +0300 Subject: [PATCH] MXS-3115: Don't process files in hidden directories Hidden directories should be treated the same was as hidden files. --- server/core/config.cc | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/server/core/config.cc b/server/core/config.cc index 92d7fd999..073b53ad4 100644 --- a/server/core/config.cc +++ b/server/core/config.cc @@ -879,6 +879,7 @@ static bool config_load_single_file(const char* file, */ static CONFIG_CONTEXT* current_ccontext; static DUPLICATE_CONTEXT* current_dcontext; +static std::unordered_set hidden_dirs; /** * The nftw callback. @@ -924,12 +925,25 @@ int config_cb(const char* fpath, const struct stat* sb, int typeflag, struct FTW } } + if (typeflag == FTW_D) + { + // Hidden directory or a directory inside a hidden directory + if (fpath[ftwbuf->base] == '.' || hidden_dirs.count(std::string(fpath, fpath + ftwbuf->base - 1))) + { + hidden_dirs.insert(fpath); + } + } + if (typeflag == FTW_F) // We are only interested in files, { const char* filename = fpath + ftwbuf->base; const char* dot = strrchr(filename, '.'); - if (dot && *filename != '.') // that have a suffix and are not hidden, + if (hidden_dirs.count(std::string(fpath, fpath + ftwbuf->base - 1))) + { + MXS_INFO("Ignoring file inside hidden directory: %s", fpath); + } + else if (dot && *filename != '.') // that have a suffix and are not hidden, { const char* suffix = dot + 1; @@ -976,6 +990,7 @@ static bool config_load_dir(const char* dir, DUPLICATE_CONTEXT* dcontext, CONFIG int rv = nftw(dir, config_cb, nopenfd, FTW_PHYS); current_ccontext = NULL; current_dcontext = NULL; + hidden_dirs.clear(); return rv == 0; }