MCPcopy Create free account
hub / github.com/Norbyte/bg3se / IsSafeRelativePath

Function IsSafeRelativePath

BG3Extender/Extender/Shared/ScriptHelpers.cpp:9–36  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7namespace bg3se::script {
8
9bool IsSafeRelativePath(STDString const& path)
10{
11 if (path.empty()) {
12 OsiError("IO path cannot be empty");
13 return false;
14 }
15
16 // File naming rules per https://learn.microsoft.com/en-us/windows/win32/fileio/naming-a-file
17 for (auto c : path) {
18 // Note: since path is UTF-8, we let all code points > 0x80 through
19 if (c < 0x20 || c == '<' || c == '>' || c == ':' || c == '"' || c == '|' || c == '?' || c == '*') {
20 OsiError("Illegal character in filename: '" << path << "'");
21 return false;
22 }
23 }
24
25 if (*path.rbegin() == ' ' || *path.rbegin() == '.') {
26 OsiError("Path cannot end with space or dot: '" << path << "'");
27 return false;
28 }
29
30 if (path.find("..") != STDString::npos) {
31 OsiError("Path cannot contain traversal: '" << path << "'");
32 return false;
33 }
34
35 return true;
36}
37
38std::optional<STDWString> GetPathForExternalIo(std::string_view scriptPath, PathRootType root)
39{

Callers 2

GetPathForExternalIoFunction · 0.85
LoadExternalFileFunction · 0.85

Calls 2

emptyMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected