[EU-FOSSA] Fix loading unexpected dll as plugin issue

Unexpect behaviour: if "<NppDir>\...dll" and/or "<NppDir>\plugins\..dll" exist, they will be loaded because Notepad++ try to load "<NppDir>\pluginName\pluginName.dll" as plugin, in our case "<NppDir>\plugins\..\...dll" and "<NppDir>\plugins\.\..dll" respectively.

The fix is excluding both directories ".." & "." to not load mentionned above unwanted dll.
This commit is contained in:
Don HO 2019-01-19 03:30:54 +01:00
parent e813f0383b
commit abf78e84b2

View File

@ -319,46 +319,53 @@ bool PluginsManager::loadPluginsV2(const TCHAR* dir)
// get plugin folder // get plugin folder
if (hFindFolder != INVALID_HANDLE_VALUE && (foundData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) if (hFindFolder != INVALID_HANDLE_VALUE && (foundData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{ {
generic_string pluginsFullPathFilter = pluginsFolder; generic_string foundFileName = foundData.cFileName;
PathAppend(pluginsFullPathFilter, foundData.cFileName); if (foundFileName != TEXT(".") && foundFileName != TEXT(".."))
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))
{ {
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(); // get plugin
pl.add(foundData.cFileName, false); 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 // get plugin folder
while (::FindNextFile(hFindFolder, &foundData)) while (::FindNextFile(hFindFolder, &foundData))
{ {
generic_string pluginsFullPathFilter2 = pluginsFolder; generic_string foundFileName2 = foundData.cFileName;
PathAppend(pluginsFullPathFilter2, foundData.cFileName); if (foundFileName2 != TEXT(".") && foundFileName2 != TEXT(".."))
generic_string pluginsFolderPath2 = pluginsFullPathFilter2;
generic_string dllName2 = foundData.cFileName;
dllName2 += TEXT(".dll");
PathAppend(pluginsFullPathFilter2, dllName2);
// get plugin
if (hFindDll)
{ {
::FindClose(hFindDll); generic_string pluginsFullPathFilter2 = pluginsFolder;
hFindDll = INVALID_HANDLE_VALUE; PathAppend(pluginsFullPathFilter2, foundFileName2);
} generic_string pluginsFolderPath2 = pluginsFullPathFilter2;
hFindDll = ::FindFirstFile(pluginsFullPathFilter2.c_str(), &foundData); generic_string dllName2 = foundFileName2;
if (hFindDll != INVALID_HANDLE_VALUE && !(foundData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) dllName2 += TEXT(".dll");
{ PathAppend(pluginsFullPathFilter2, dllName2);
dllNames.push_back(pluginsFullPathFilter2);
PluginList & pl = nppParams->getPluginList(); // get plugin
pl.add(foundData.cFileName, false); 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);
}
} }
} }