Skip to content

Commit

Permalink
[EU-FOSSA] Fix loading unexpected dll as plugin issue
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
donho committed Jan 19, 2019
1 parent e813f03 commit abf78e8
Showing 1 changed file with 39 additions and 32 deletions.
71 changes: 39 additions & 32 deletions PowerEditor/src/MISC/PluginsManager/PluginsManager.cpp
Expand Up @@ -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);

// 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(foundData.cFileName, false);
PluginList & pl = nppParams->getPluginList();
pl.add(foundFileName2, false);
}
}
}

Expand Down

0 comments on commit abf78e8

Please sign in to comment.