]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/script/cpp_api/s_security.cpp
Order es_DrawType exactly like enum NodeDrawType in nodedef.h (#5946)
[dragonfireclient.git] / src / script / cpp_api / s_security.cpp
index c6aad71b8e896321f3058de1cf8e9d5bb18b4d38..5ad7947d5f6791bce4d8475a2887fd693623a765 100644 (file)
@@ -123,6 +123,7 @@ void ScriptApiSecurity::initializeSecurity()
                "path",
                "searchpath",
        };
+#if USE_LUAJIT
        static const char *jit_whitelist[] = {
                "arch",
                "flush",
@@ -134,7 +135,7 @@ void ScriptApiSecurity::initializeSecurity()
                "version",
                "version_num",
        };
-
+#endif
        m_secure = true;
 
        lua_State *L = getStack();
@@ -245,13 +246,6 @@ void ScriptApiSecurity::initializeSecurityClient()
                "table",
                "math",
        };
-       static const char *io_whitelist[] = {
-               "close",
-               "flush",
-               "read",
-               "type",
-               "write",
-       };
        static const char *os_whitelist[] = {
                "clock",
                "date",
@@ -263,6 +257,7 @@ void ScriptApiSecurity::initializeSecurityClient()
                "getinfo",
        };
 
+#if USE_LUAJIT
        static const char *jit_whitelist[] = {
                "arch",
                "flush",
@@ -274,6 +269,7 @@ void ScriptApiSecurity::initializeSecurityClient()
                "version",
                "version_num",
        };
+#endif
 
        m_secure = true;
 
@@ -294,20 +290,6 @@ void ScriptApiSecurity::initializeSecurityClient()
        lua_pop(L, 1);
 
 
-       // Copy safe IO functions
-       lua_getfield(L, old_globals, "io");
-       lua_newtable(L);
-       copy_safe(L, io_whitelist, sizeof(io_whitelist));
-
-       // And replace unsafe ones
-       SECURE_API(io, open);
-       SECURE_API(io, input);
-       SECURE_API(io, output);
-       SECURE_API(io, lines);
-
-       lua_setglobal(L, "io");
-       lua_pop(L, 1);  // Pop old IO
-
 
        // Copy safe OS functions
        lua_getfield(L, old_globals, "os");
@@ -324,10 +306,6 @@ void ScriptApiSecurity::initializeSecurityClient()
        lua_setglobal(L, "debug");
        lua_pop(L, 1);  // Pop old debug
 
-       // Remove all of package
-       lua_newtable(L);
-       lua_setglobal(L, "package");
-
 #if USE_LUAJIT
        // Copy safe jit functions, if they exist
        lua_getfield(L, -1, "jit");
@@ -428,7 +406,14 @@ bool ScriptApiSecurity::safeLoadFile(lua_State *L, const char *path)
 
        // Read the file
        int ret = std::fseek(fp, 0, SEEK_END);
-       CHECK_FILE_ERR(ret, fp);
+       if (ret) {
+               lua_pushfstring(L, "%s: %s", path, strerror(errno));
+               std::fclose(fp);
+               if (path) {
+                       delete [] chunk_name;
+               }
+               return false;
+       }
 
        size_t size = std::ftell(fp) - start;
        char *code = new char[size];