From c4258759b4d004fce42e2c45c14ed892860861bc Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Mon, 19 Nov 2018 20:48:04 +0100 Subject: [PATCH 1/3] Make sure directories aren't falsely recognized as plugins --- src/plugin/plugin.cpp | 53 +++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/src/plugin/plugin.cpp b/src/plugin/plugin.cpp index 0defbf9c..48c0b279 100644 --- a/src/plugin/plugin.cpp +++ b/src/plugin/plugin.cpp @@ -65,29 +65,42 @@ namespace linuxdeploy { ldLog() << LD_DEBUG << "Searching for plugins in directory" << dir << std::endl; for (bf::directory_iterator i(dir); i != bf::directory_iterator(); ++i) { + // must be a file, and not a directory + if (!(bf::is_directory(bf::absolute(*i)))) { + ldLog() << LD_DEBUG << "Entry is a directory, skipping:" << i->path() << std::endl; + continue; + } + // file must be executable... - if (bf::status(*i).permissions() & (bf::owner_exe | bf::group_exe | bf::others_exe)) { - // ... and filename must match regular expression - boost::cmatch res; - if (boost::regex_match(i->path().filename().string().c_str(), res, PLUGIN_EXPR)) { - try { - auto name = res[1].str(); - auto* plugin = createPluginInstance(*i); - if (plugin == nullptr) { - ldLog() << LD_DEBUG << "Failed to create instance for plugin" << i->path(); - } else { - ldLog() << LD_DEBUG << "Found plugin '" << LD_NO_SPACE << name << LD_NO_SPACE << "':" << plugin->path() << std::endl; - - if (foundPlugins.find(name) != foundPlugins.end()) { - ldLog() << LD_DEBUG << "Already found" << name << "plugin in" << foundPlugins[name]->path() << std::endl; - } else { - foundPlugins[name] = plugin; - } - } - } catch (const PluginError& e) { - ldLog() << LD_WARNING << "Could not load plugin" << i->path() << LD_NO_SPACE << ": " << e.what(); + if (!(bf::status(*i).permissions() & (bf::owner_exe | bf::group_exe | bf::others_exe))) { + ldLog() << LD_DEBUG << "File/symlink is not executable, skipping:" << i->path() << std::endl; + continue; + } + + // entry name must match regular expression + boost::cmatch res; + + if (!boost::regex_match(i->path().filename().string().c_str(), res, PLUGIN_EXPR)) { + ldLog() << LD_DEBUG << "Doesn't match plugin regex, skipping:" << i->path() << std::endl; + continue; + } + + try { + auto name = res[1].str(); + auto* plugin = createPluginInstance(*i); + if (plugin == nullptr) { + ldLog() << LD_DEBUG << "Failed to create instance for plugin" << i->path() << std::endl;; + } else { + ldLog() << LD_DEBUG << "Found plugin '" << LD_NO_SPACE << name << LD_NO_SPACE << "':" << plugin->path() << std::endl; + + if (foundPlugins.find(name) != foundPlugins.end()) { + ldLog() << LD_DEBUG << "Already found" << name << "plugin in" << foundPlugins[name]->path() << std::endl; + } else { + foundPlugins[name] = plugin; } } + } catch (const PluginError& e) { + ldLog() << LD_WARNING << "Could not load plugin" << i->path() << LD_NO_SPACE << ": " << e.what(); } } } From 6f7a2fd54aebfcf85e2eb4df00b2e21c4971fcde Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Mon, 19 Nov 2018 20:50:09 +0100 Subject: [PATCH 2/3] Reduce verbosity of debug logging related to plugin detection --- src/plugin/plugin.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/plugin/plugin.cpp b/src/plugin/plugin.cpp index 48c0b279..c178088b 100644 --- a/src/plugin/plugin.cpp +++ b/src/plugin/plugin.cpp @@ -64,16 +64,22 @@ namespace linuxdeploy { ldLog() << LD_DEBUG << "Searching for plugins in directory" << dir << std::endl; + bool extendedDebugLoggingEnabled = (getenv("DEBUG_PLUGIN_DETECTION") != nullptr); + for (bf::directory_iterator i(dir); i != bf::directory_iterator(); ++i) { // must be a file, and not a directory if (!(bf::is_directory(bf::absolute(*i)))) { - ldLog() << LD_DEBUG << "Entry is a directory, skipping:" << i->path() << std::endl; + if (extendedDebugLoggingEnabled) + ldLog() << LD_DEBUG << "Entry is a directory, skipping:" << i->path() << std::endl; + continue; } // file must be executable... if (!(bf::status(*i).permissions() & (bf::owner_exe | bf::group_exe | bf::others_exe))) { - ldLog() << LD_DEBUG << "File/symlink is not executable, skipping:" << i->path() << std::endl; + if (extendedDebugLoggingEnabled) + ldLog() << LD_DEBUG << "File/symlink is not executable, skipping:" << i->path() << std::endl; + continue; } From 132931772c272cf76a16ca79a4eac2ba80111497 Mon Sep 17 00:00:00 2001 From: TheAssassin Date: Mon, 19 Nov 2018 20:52:45 +0100 Subject: [PATCH 3/3] Fix directory check --- src/plugin/plugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugin/plugin.cpp b/src/plugin/plugin.cpp index c178088b..4b34943b 100644 --- a/src/plugin/plugin.cpp +++ b/src/plugin/plugin.cpp @@ -68,7 +68,7 @@ namespace linuxdeploy { for (bf::directory_iterator i(dir); i != bf::directory_iterator(); ++i) { // must be a file, and not a directory - if (!(bf::is_directory(bf::absolute(*i)))) { + if (bf::is_directory(bf::absolute(*i))) { if (extendedDebugLoggingEnabled) ldLog() << LD_DEBUG << "Entry is a directory, skipping:" << i->path() << std::endl;