fs: Prevent the BFS version of get_wml_location() from escaping the data dir

This is essentially a port to the BFS implementation of the fs API of
commits 314425ab0e and
9f458d1bb2, 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.
This commit is contained in:
Ignacio R. Morelle 2015-04-04 23:27:16 -03:00
parent 2897436c06
commit 001d20e2ff

View file

@ -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;
@ -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;
}