aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan <sentrycraft123@gmail.com>2023-07-29 22:48:24 +0200
committerGitHub <noreply@github.com>2023-07-29 22:48:24 +0200
commit0af8c500aecb2eca77996e9ef750589fceb7245b (patch)
treea308050a2fb9cb21d9c45dd96d8699a4117ce672
parente3f2c4c6622c83ac561f7e4cbf8601c50469d291 (diff)
downloadNorthstarLauncher-1.18.0-rc1.tar.gz
NorthstarLauncher-1.18.0-rc1.zip
Validate package pattern before checking for plugins (#525)v1.18.0-rc1v1.18.0
Adds missing validation check to ensure that the package folder the plugin is included in matches the `AUTHOR-MOD-VERSION` pattern.
-rw-r--r--NorthstarDLL/mods/modmanager.cpp1
-rw-r--r--NorthstarDLL/plugins/plugins.cpp21
2 files changed, 16 insertions, 6 deletions
diff --git a/NorthstarDLL/mods/modmanager.cpp b/NorthstarDLL/mods/modmanager.cpp
index bf63fc41..044ec6d4 100644
--- a/NorthstarDLL/mods/modmanager.cpp
+++ b/NorthstarDLL/mods/modmanager.cpp
@@ -16,6 +16,7 @@
#include <string>
#include <sstream>
#include <vector>
+#include <regex>
ModManager* g_pModManager;
diff --git a/NorthstarDLL/plugins/plugins.cpp b/NorthstarDLL/plugins/plugins.cpp
index 6ccd348e..0c4c7fd6 100644
--- a/NorthstarDLL/plugins/plugins.cpp
+++ b/NorthstarDLL/plugins/plugins.cpp
@@ -7,6 +7,7 @@
#include "core/convar/convar.h"
#include "server/serverpresence.h"
#include <optional>
+#include <regex>
#include "util/version.h"
#include "pluginbackend.h"
@@ -215,7 +216,7 @@ bool PluginManager::LoadPlugins()
std::vector<fs::path> paths;
- pluginPath = GetNorthstarPrefix() + "/plugins";
+ pluginPath = GetNorthstarPrefix() + "\\plugins";
PluginNorthstarData data {};
std::string ns_version {version};
@@ -232,12 +233,20 @@ bool PluginManager::LoadPlugins()
FindPlugins(pluginPath, paths);
- // Special case for Thunderstore plugin dirs
-
- for (fs::directory_entry dir : fs::directory_iterator(GetThunderstoreModFolderPath()))
+ // Special case for Thunderstore mods dir
+ std::filesystem::directory_iterator thunderstoreModsDir = fs::directory_iterator(GetThunderstoreModFolderPath());
+ // Set up regex for `AUTHOR-MOD-VERSION` pattern
+ std::regex pattern(R"(.*\\([a-zA-Z0-9_]+)-([a-zA-Z0-9_]+)-(\d+\.\d+\.\d+))");
+ for (fs::directory_entry dir : thunderstoreModsDir)
{
- fs::path pluginDir = dir.path() / "plugins";
- FindPlugins(pluginDir, paths);
+ fs::path pluginsDir = dir.path() / "plugins";
+ // Use regex to match `AUTHOR-MOD-VERSION` pattern
+ if (!std::regex_match(dir.path().string(), pattern))
+ {
+ spdlog::warn("The following directory did not match 'AUTHOR-MOD-VERSION': {}", dir.path().string());
+ continue; // skip loading package that doesn't match
+ }
+ FindPlugins(pluginsDir, paths);
}
if (paths.empty())