@@ -27,12 +27,36 @@ with this program; if not, write to the Free Software Foundation, Inc.,
27
27
#include " log.h"
28
28
29
29
30
- #define SET_SECURITY_CHECK (L, name ) \
31
- if (o->m_settings == g_settings && ScriptApiSecurity::isSecure(L) && \
32
- name.compare(0 , 7 , " secure." ) == 0 ) { \
33
- throw LuaError (" Attempt to set secure setting." ); \
30
+ /* This protects:
31
+ * 'secure.*' settings from being set
32
+ * some mapgen settings from being set
33
+ * (not security-criticial, just to avoid messing up user configs)
34
+ */
35
+ #define CHECK_SETTING_SECURITY (L, name ) \
36
+ if (o->m_settings == g_settings) { \
37
+ if (checkSettingSecurity (L, name) == -1 ) \
38
+ return 0 ; \
34
39
}
35
40
41
+ static inline int checkSettingSecurity (lua_State* L, const std::string &name)
42
+ {
43
+ if (ScriptApiSecurity::isSecure (L) && name.compare (0 , 7 , " secure." ) == 0 )
44
+ throw LuaError (" Attempt to set secure setting." );
45
+
46
+ bool is_mainmenu = false ;
47
+ #ifndef SERVER
48
+ is_mainmenu = ModApiBase::getGuiEngine (L) != nullptr ;
49
+ #endif
50
+ if (!is_mainmenu && (name == " mg_name" || name == " mg_flags" )) {
51
+ errorstream << " Tried to set global setting " << name << " , ignoring. "
52
+ " minetest.set_mapgen_setting() should be used instead." << std::endl;
53
+ infostream << script_get_backtrace (L) << std::endl;
54
+ return -1 ;
55
+ }
56
+
57
+ return 0 ;
58
+ }
59
+
36
60
LuaSettings::LuaSettings (Settings *settings, const std::string &filename) :
37
61
m_settings(settings),
38
62
m_filename(filename)
@@ -130,6 +154,7 @@ int LuaSettings::l_get_np_group(lua_State *L)
130
154
return 1 ;
131
155
}
132
156
157
+ // get_flags(self, key) -> table or nil
133
158
int LuaSettings::l_get_flags (lua_State *L)
134
159
{
135
160
NO_MAP_LOCK_REQUIRED;
@@ -162,7 +187,7 @@ int LuaSettings::l_set(lua_State* L)
162
187
std::string key = std::string (luaL_checkstring (L, 2 ));
163
188
const char * value = luaL_checkstring (L, 3 );
164
189
165
- SET_SECURITY_CHECK (L, key);
190
+ CHECK_SETTING_SECURITY (L, key);
166
191
167
192
if (!o->m_settings ->set (key, value))
168
193
throw LuaError (" Invalid sequence found in setting parameters" );
@@ -179,14 +204,14 @@ int LuaSettings::l_set_bool(lua_State* L)
179
204
std::string key = std::string (luaL_checkstring (L, 2 ));
180
205
bool value = readParam<bool >(L, 3 );
181
206
182
- SET_SECURITY_CHECK (L, key);
207
+ CHECK_SETTING_SECURITY (L, key);
183
208
184
209
o->m_settings ->setBool (key, value);
185
210
186
- return 1 ;
211
+ return 0 ;
187
212
}
188
213
189
- // set (self, key, value)
214
+ // set_np_group (self, key, value)
190
215
int LuaSettings::l_set_np_group (lua_State *L)
191
216
{
192
217
NO_MAP_LOCK_REQUIRED;
@@ -196,7 +221,7 @@ int LuaSettings::l_set_np_group(lua_State *L)
196
221
NoiseParams value;
197
222
read_noiseparams (L, 3 , &value);
198
223
199
- SET_SECURITY_CHECK (L, key);
224
+ CHECK_SETTING_SECURITY (L, key);
200
225
201
226
o->m_settings ->setNoiseParams (key, value);
202
227
@@ -211,7 +236,7 @@ int LuaSettings::l_remove(lua_State* L)
211
236
212
237
std::string key = std::string (luaL_checkstring (L, 2 ));
213
238
214
- SET_SECURITY_CHECK (L, key);
239
+ CHECK_SETTING_SECURITY (L, key);
215
240
216
241
bool success = o->m_settings ->remove (key);
217
242
lua_pushboolean (L, success);
0 commit comments