mirror of
https://github.com/sfall-team/sfall.git
synced 2026-07-27 16:52:34 -07:00
mods_order: remove comments before other checks, to prevent valid paths being ignored
This commit is contained in:
@@ -266,19 +266,26 @@ static void __fastcall game_init_databases_hook1() {
|
||||
*/
|
||||
static bool NormalizePath(std::string &path) {
|
||||
const char* whiteSpaces = " \t";
|
||||
std::size_t pos;
|
||||
if (path.find(':') != std::string::npos) return false;
|
||||
|
||||
std::replace(path.begin(), path.end(), '/', '\\');
|
||||
|
||||
if (path.find(".\\") != std::string::npos || path.find("..\\") != std::string::npos) return false;
|
||||
pos = path.find_first_of(";#"); // comments
|
||||
// Remove comments
|
||||
std::size_t pos = path.find_first_of(";#");
|
||||
if (pos != std::string::npos) {
|
||||
path.erase(pos);
|
||||
}
|
||||
// Skip paths with colons.
|
||||
if (path.find(':') != std::string::npos) return false;
|
||||
|
||||
// Normalize directory separators.
|
||||
std::replace(path.begin(), path.end(), '/', '\\');
|
||||
|
||||
// Disallow paths going outside of root folder.
|
||||
if (path.find(".\\") != std::string::npos || path.find("..\\") != std::string::npos) return false;
|
||||
|
||||
// Trim whitespaces.
|
||||
path.erase(0, path.find_first_not_of(whiteSpaces)); // trim left
|
||||
path.erase(path.find_last_not_of(whiteSpaces) + 1); // trim right
|
||||
path.erase(0, path.find_first_not_of('\\')); // remove firsts '\'
|
||||
|
||||
// Remove leading slashes.
|
||||
path.erase(0, path.find_first_not_of('\\'));
|
||||
return !path.empty();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user