Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harden plugin loading path requirements #1437

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion core/logic/ExtensionSys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -631,9 +631,15 @@ IExtension *CExtensionManager::FindExtensionByName(const char *ext)

IExtension *CExtensionManager::LoadExtension(const char *file, char *error, size_t maxlength)
{
if (strstr(file, "..") != NULL)
{
ke::SafeStrcpy(error, maxlength, "Cannot load extensions outside the \"extensions\" folder.");
return NULL;
}

/* Remove platform extension if it's there. Compat hack. */
const char *ext = libsys->GetFileExtension(file);
if (strcmp(ext, PLATFORM_LIB_EXT) == 0)
if (ext && strcmp(ext, PLATFORM_LIB_EXT) == 0)
{
char path2[PLATFORM_MAX_PATH];
ke::SafeStrcpy(path2, sizeof(path2), file);
Expand Down
14 changes: 14 additions & 0 deletions core/logic/PluginSys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,20 @@ IPlugin *CPluginManager::LoadPlugin(const char *path, bool debug, PluginType typ
LoadRes res;

*wasloaded = false;

if (strstr(path, "..") != NULL)
{
ke::SafeStrcpy(error, maxlength, "Cannot load plugins outside the \"plugins\" folder");
return NULL;
}

const char *ext = libsys->GetFileExtension(path);
if (!ext || strcmp(ext, "smx") != 0)
KyleSanderson marked this conversation as resolved.
Show resolved Hide resolved
{
ke::SafeStrcpy(error, maxlength, "Plugin files must have the \".smx\" file extension");
return NULL;
}

if ((res=LoadPlugin(&pl, path, true, PluginType_MapUpdated)) == LoadRes_Failure)
{
ke::SafeStrcpy(error, maxlength, pl->GetErrorMsg());
Expand Down