Skip to content

Commit

Permalink
fs: Prevent the BFS version of get_wml_location() from escaping the d…
Browse files Browse the repository at this point in the history
…ata dir

This is essentially a port to the BFS implementation of the fs API of
commits 314425a and
9f458d1, which were authored separately
from the BFS branch.

Note that this introduces another disparity in behavior between the BFS
and legacy implementations of this API, in that the BFS
get_wml_location() function will now always start at <data dir>/data/
instead of starting at <data dir> in obscure border cases. This is
expected to have no impact on anything at all for reasons discussed on
IRC.
  • Loading branch information
irydacea committed Apr 5, 2015
1 parent 2897436 commit 001d20e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/filesystem_boost.cpp
Expand Up @@ -1074,6 +1074,8 @@ std::string get_wml_location(const std::string &filename, const std::string &cur
if (!is_legal_file(filename))
return std::string();

assert(game_config::path.empty() == false);

path fpath(filename);
path result;

Expand All @@ -1082,7 +1084,13 @@ std::string get_wml_location(const std::string &filename, const std::string &cur
result /= get_user_data_path() / "data" / filename.substr(1);
DBG_FS << " trying '" << result.string() << "'\n";
} else if (*fpath.begin() == ".") {
result /= path(current_dir) / filename;
if (!current_dir.empty()) {
result /= path(current_dir);
} else {
result /= path(game_config::path) / "data";
}

result /= filename;
} else if (!game_config::path.empty()) {
result /= path(game_config::path) / "data" / filename;
}
Expand Down

0 comments on commit 001d20e

Please sign in to comment.