diff --git a/CHANGES b/CHANGES index 850ca693f2..a87d486f22 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,8 @@ +4.1.0-dev.318 | 2021-03-10 12:05:47 -0800 + + * Avoid searching a directory for dynamic plugins multiple times (Jon Siwek, Corelight) + 4.1.0-dev.316 | 2021-03-10 13:00:27 +0000 * Fix potential mime type detection bug in IRC/FTP file_transferred event diff --git a/VERSION b/VERSION index 99ca693f60..a19cf70fbf 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.1.0-dev.316 +4.1.0-dev.318 diff --git a/src/plugin/Manager.cc b/src/plugin/Manager.cc index d629455dae..da4ff5fe32 100644 --- a/src/plugin/Manager.cc +++ b/src/plugin/Manager.cc @@ -7,6 +7,8 @@ #include #include #include +#include // for PATH_MAX +#include #include #include #include @@ -70,6 +72,19 @@ void Manager::SearchDynamicPlugins(const std::string& dir) return; } + char canon_path[PATH_MAX]; + if ( ! realpath(dir.data(), canon_path) ) + { + DBG_LOG(DBG_PLUGINS, "skip dynamic plugin search in %s, realpath failed: %s", + dir.data(), strerror(errno)); + return; + } + + if ( searched_dirs.count(canon_path) ) + return; + + searched_dirs.emplace(canon_path); + // Check if it's a plugin dirctory. const std::string magic = dir + "/__bro_plugin__"; diff --git a/src/plugin/Manager.h b/src/plugin/Manager.h index c97a411304..6af81e7b96 100644 --- a/src/plugin/Manager.h +++ b/src/plugin/Manager.h @@ -416,6 +416,11 @@ private: void MetaHookPre(HookType hook, const HookArgumentList& args) const; void MetaHookPost(HookType hook, const HookArgumentList& args, const HookArgument& result) const; + // Directories that have already been searched for dynamic plugins. + // Used to prevent multiple searches of the same dirs (e.g. via symlinks). + // The paths stored in the set are made canonical via realpath(). + std::set> searched_dirs; + // Plugins that were explicitly requested to be activated, but failed to // load at first. std::set requested_plugins;