Skip to content

Commit ef925bc

Browse files
committed
Disallow loading plugins with the same name when they exist in sub dirs
1 parent df8bdfe commit ef925bc

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/dbg/plugin_loader.cpp

+19-14
Original file line numberDiff line numberDiff line change
@@ -92,19 +92,24 @@ static std::string pluginGetFullPath(std::string pluginName)
9292
{
9393
std::string pluginPath = StringUtils::Utf16ToUtf8(pluginDirectory) + "\\" + pluginName;
9494

95-
// Check if the plugin is a directory.
96-
if(PathIsDirectoryW(StringUtils::Utf8ToUtf16(pluginPath).c_str()))
95+
// Check if the plugin is in a sub-directory.
96+
std::string pluginPathSubdir = pluginPath + "\\" + pluginName + pluginExtension;
97+
if(PathIsDirectoryW(StringUtils::Utf8ToUtf16(pluginPathSubdir).c_str()))
9798
{
98-
// Plugin is probably inside the directory.
99-
pluginPath += "\\" + pluginName + pluginExtension;
99+
// Plugin resides in sub directory.
100+
return pluginPathSubdir;
100101
}
101-
else
102+
103+
// Check if plugin is from the main plugin directory.
104+
std::string pluginPathWithExt = pluginPath + pluginExtension;
105+
if(PathFileExistsW(StringUtils::Utf8ToUtf16(pluginPathWithExt).c_str()))
102106
{
103-
// Ordinary file
104-
pluginPath += pluginExtension;
107+
// Plugin resides in main plugins directory.
108+
return pluginPathWithExt;
105109
}
106110

107-
return pluginPath;
111+
// Unable to determine the full path to the plugin, probably doesn't exist.
112+
return "";
108113
}
109114

110115
/**
@@ -133,17 +138,17 @@ bool pluginload(const char* pluginName, bool loadall)
133138
}
134139

135140
//Check to see if this plugin is already loaded
136-
if(!loadall)
141+
EXCLUSIVE_ACQUIRE(LockPluginList);
142+
for(auto it = pluginList.begin(); it != pluginList.end(); ++it)
137143
{
138-
EXCLUSIVE_ACQUIRE(LockPluginList);
139-
for(auto it = pluginList.begin(); it != pluginList.end(); ++it)
144+
if(_stricmp(it->plugname, name.c_str()) == 0)
140145
{
141-
if(_stricmp(it->plugname, name.c_str()) == 0)
146+
dprintf(QT_TRANSLATE_NOOP("DBG", "[PLUGIN] %s already loaded\n"), it->plugname);
147+
if(!loadall)
142148
{
143-
dprintf(QT_TRANSLATE_NOOP("DBG", "[PLUGIN] %s already loaded\n"), it->plugname);
144149
SetCurrentDirectoryW(currentDir);
145-
return false;
146150
}
151+
return false;
147152
}
148153
}
149154

0 commit comments

Comments
 (0)