| 7 | namespace bg3se::script { |
| 8 | |
| 9 | bool 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 | |
| 38 | std::optional<STDWString> GetPathForExternalIo(std::string_view scriptPath, PathRootType root) |
| 39 | { |
no test coverage detected