Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PauseMenuScripting: resolve absolute 'builtin' path before substring check #15720

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/script/cpp_api/s_security.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ int ScriptApiSecurity::sl_g_loadfile(lua_State *L)
std::string path = readParam<std::string>(L, 1);
const std::string *contents = script->getClient()->getModFile(path);
if (!contents) {
std::string error_msg = "Coudln't find script called: " + path;
std::string error_msg = "Couldn't find script called: " + path;
lua_pushnil(L);
lua_pushstring(L, error_msg.c_str());
return 2;
Expand Down
8 changes: 5 additions & 3 deletions src/script/scripting_pause_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void PauseMenuScripting::initializeModApi(lua_State *L, int top)

void PauseMenuScripting::loadBuiltin()
{
loadScript(porting::path_share + DIR_DELIM "builtin" DIR_DELIM "init.lua");
loadScript(Client::getBuiltinLuaPath() + DIR_DELIM "init.lua");
checkSetByBuiltin();
}

Expand All @@ -60,9 +60,11 @@ bool PauseMenuScripting::checkPathInternal(const std::string &abs_path, bool wri
// NOTE: The pause menu env is on the same level of trust as the mainmenu env.
// However, since it doesn't need anything else at the moment, there's no
// reason to give it access to anything else.
// See also: `MainMenuScripting::mayModifyPath` for similar, but less restricted checks.

if (write_required)
return false;
std::string path_share = fs::AbsolutePath(porting::path_share);
return !path_share.empty() && fs::PathStartsWith(abs_path, path_share + DIR_DELIM "builtin");

std::string path_builtin = fs::AbsolutePath(Client::getBuiltinLuaPath());
return !path_builtin.empty() && fs::PathStartsWith(abs_path, path_builtin);
}
Loading