From f493e73aeb65a0f4f4ad8a93ef4f4dbf197d606d Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 18 Nov 2024 23:58:42 +0100 Subject: [PATCH] Fix changing secure settings from mainmenu forgotten in ea4ae55e24d2c27524490cb8e0d3c34aa46e3da3 closes #15454 --- src/script/lua_api/l_settings.cpp | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/script/lua_api/l_settings.cpp b/src/script/lua_api/l_settings.cpp index f3f1a57bf..c4395e390 100644 --- a/src/script/lua_api/l_settings.cpp +++ b/src/script/lua_api/l_settings.cpp @@ -12,11 +12,12 @@ #include "log.h" -/* This protects the following from being set: - * 'secure.*' settings - * some security-relevant settings +/* + * This protects the following from being set: + * - 'secure.*' settings + * - some security-relevant settings * (better solution pending) - * some mapgen settings + * - some mapgen settings * (not security-criticial, just to avoid messing up user configs) */ #define CHECK_SETTING_SECURITY(L, name) \ @@ -27,14 +28,16 @@ static inline int checkSettingSecurity(lua_State* L, const std::string &name) { +#if CHECK_CLIENT_BUILD() + // Main menu is allowed everything + if (ModApiBase::getGuiEngine(L) != nullptr) + return 0; +#endif + if (ScriptApiSecurity::isSecure(L) && name.compare(0, 7, "secure.") == 0) throw LuaError("Attempted to set secure setting."); - bool is_mainmenu = false; -#if CHECK_CLIENT_BUILD() - is_mainmenu = ModApiBase::getGuiEngine(L) != nullptr; -#endif - if (!is_mainmenu && (name == "mg_name" || name == "mg_flags")) { + if (name == "mg_name" || name == "mg_flags") { errorstream << "Tried to set global setting " << name << ", ignoring. " "minetest.set_mapgen_setting() should be used instead." << std::endl; infostream << script_get_backtrace(L) << std::endl; @@ -45,11 +48,9 @@ static inline int checkSettingSecurity(lua_State* L, const std::string &name) "main_menu_script", "shader_path", "texture_path", "screenshot_path", "serverlist_file", "serverlist_url", "map-dir", "contentdb_url", }; - if (!is_mainmenu) { - for (const char *name2 : disallowed) { - if (name == name2) - throw LuaError("Attempted to set disallowed setting."); - } + for (const char *name2 : disallowed) { + if (name == name2) + throw LuaError("Attempted to set disallowed setting."); } return 0;