Use LuaErrors in security check macros
authorShadowNinja <shadowninja@minetest.net>
Sun, 6 Mar 2016 19:41:26 +0000 (14:41 -0500)
committerShadowNinja <shadowninja@minetest.net>
Mon, 7 Mar 2016 18:37:15 +0000 (13:37 -0500)
Throwing a LuaError calls destructors as it propagates up the stack,
wheres lua_error just executes a longjmp.

src/script/cpp_api/s_security.h
src/script/lua_api/l_util.cpp

index 4a4389cf5187bbd9594ba123871be78899819e27..97bc5c0671bc5876d25873f171f191e7f4c67805 100644 (file)
@@ -25,9 +25,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 
 #define CHECK_SECURE_PATH(L, path) \
        if (!ScriptApiSecurity::checkPath(L, path)) { \
-               lua_pushstring(L, (std::string("Attempt to access external file ") + \
-                                       path + " with mod security on.").c_str()); \
-               lua_error(L); \
+               throw LuaError(std::string("Attempt to access external file ") + \
+                                       path + " with mod security on."); \
        }
 #define CHECK_SECURE_PATH_OPTIONAL(L, path) \
        if (ScriptApiSecurity::isSecure(L)) { \
index df46925d184e2b08fd33bf1c0a90388b304f5819..98f70d917c2b5fce66f3d98864b50c06ddea985d 100644 (file)
@@ -77,8 +77,7 @@ int ModApiUtil::l_get_us_time(lua_State *L)
 #define CHECK_SECURE_SETTING(L, name) \
        if (ScriptApiSecurity::isSecure(L) && \
                        name.compare(0, 7, "secure.") == 0) { \
-               lua_pushliteral(L, "Attempt to set secure setting."); \
-               lua_error(L); \
+               throw LuaError("Attempt to set secure setting."); \
        }
 
 // setting_set(name, value)