From abf78e84b2a596832bdc2f95b4ad424798a47dab Mon Sep 17 00:00:00 2001 From: Don HO Date: Sat, 19 Jan 2019 03:30:54 +0100 Subject: [PATCH] [EU-FOSSA] Fix loading unexpected dll as plugin issue Unexpect behaviour: if "\...dll" and/or "\plugins\..dll" exist, they will be loaded because Notepad++ try to load "\pluginName\pluginName.dll" as plugin, in our case "\plugins\..\...dll" and "\plugins\.\..dll" respectively. The fix is excluding both directories ".." & "." to not load mentionned above unwanted dll. --- .../MISC/PluginsManager/PluginsManager.cpp | 71 ++++++++++--------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp index b30430cd..5158e36c 100644 --- a/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp +++ b/PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp @@ -319,46 +319,53 @@ bool PluginsManager::loadPluginsV2(const TCHAR* dir) // get plugin folder if (hFindFolder != INVALID_HANDLE_VALUE && (foundData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { - generic_string pluginsFullPathFilter = pluginsFolder; - PathAppend(pluginsFullPathFilter, foundData.cFileName); - generic_string pluginsFolderPath = pluginsFullPathFilter; - generic_string dllName = foundData.cFileName; - dllName += TEXT(".dll"); - PathAppend(pluginsFullPathFilter, dllName); - - // get plugin - hFindDll = ::FindFirstFile(pluginsFullPathFilter.c_str(), &foundData); - if (hFindDll != INVALID_HANDLE_VALUE && !(foundData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) + generic_string foundFileName = foundData.cFileName; + if (foundFileName != TEXT(".") && foundFileName != TEXT("..")) { - dllNames.push_back(pluginsFullPathFilter); + generic_string pluginsFullPathFilter = pluginsFolder; + PathAppend(pluginsFullPathFilter, foundFileName); + generic_string pluginsFolderPath = pluginsFullPathFilter; + generic_string dllName = foundFileName; + dllName += TEXT(".dll"); + PathAppend(pluginsFullPathFilter, dllName); - PluginList & pl = nppParams->getPluginList(); - pl.add(foundData.cFileName, false); + // get plugin + hFindDll = ::FindFirstFile(pluginsFullPathFilter.c_str(), &foundData); + if (hFindDll != INVALID_HANDLE_VALUE && !(foundData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) + { + dllNames.push_back(pluginsFullPathFilter); + + PluginList & pl = nppParams->getPluginList(); + pl.add(foundFileName, false); + } } - // get plugin folder while (::FindNextFile(hFindFolder, &foundData)) { - generic_string pluginsFullPathFilter2 = pluginsFolder; - PathAppend(pluginsFullPathFilter2, foundData.cFileName); - generic_string pluginsFolderPath2 = pluginsFullPathFilter2; - generic_string dllName2 = foundData.cFileName; - dllName2 += TEXT(".dll"); - PathAppend(pluginsFullPathFilter2, dllName2); - - // get plugin - if (hFindDll) + generic_string foundFileName2 = foundData.cFileName; + if (foundFileName2 != TEXT(".") && foundFileName2 != TEXT("..")) { - ::FindClose(hFindDll); - hFindDll = INVALID_HANDLE_VALUE; - } - hFindDll = ::FindFirstFile(pluginsFullPathFilter2.c_str(), &foundData); - if (hFindDll != INVALID_HANDLE_VALUE && !(foundData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) - { - dllNames.push_back(pluginsFullPathFilter2); + generic_string pluginsFullPathFilter2 = pluginsFolder; + PathAppend(pluginsFullPathFilter2, foundFileName2); + generic_string pluginsFolderPath2 = pluginsFullPathFilter2; + generic_string dllName2 = foundFileName2; + dllName2 += TEXT(".dll"); + PathAppend(pluginsFullPathFilter2, dllName2); - PluginList & pl = nppParams->getPluginList(); - pl.add(foundData.cFileName, false); + // get plugin + if (hFindDll) + { + ::FindClose(hFindDll); + hFindDll = INVALID_HANDLE_VALUE; + } + hFindDll = ::FindFirstFile(pluginsFullPathFilter2.c_str(), &foundData); + if (hFindDll != INVALID_HANDLE_VALUE && !(foundData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) + { + dllNames.push_back(pluginsFullPathFilter2); + + PluginList & pl = nppParams->getPluginList(); + pl.add(foundFileName2, false); + } } }