Skip to content

Commit

Permalink
Remove unsafe functions from base lua library, those should never hav…
Browse files Browse the repository at this point in the history
…e been available.
  • Loading branch information
daid committed May 16, 2024
1 parent 1f1ef09 commit 268ed7c
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/scriptInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@ void ScriptObject::createLuaState()
}
}

//Remove unsafe base functions.
lua_pushnil(L);
lua_setglobal(L, "collectgarbage");
lua_pushnil(L);
lua_setglobal(L, "dofile");
lua_pushnil(L);
lua_setglobal(L, "getmetatable");
lua_pushnil(L);
lua_setglobal(L, "loadfile");
lua_pushnil(L);
lua_setglobal(L, "load");
lua_pushnil(L);
lua_setglobal(L, "rawequal");
lua_pushnil(L);
lua_setglobal(L, "setmetatable");

//Setup a new table as the first upvalue. This will be used as "global" environment for the script. And thus will prevent global namespace polution.
lua_newtable(L); /* environment for loaded function */

Expand Down

0 comments on commit 268ed7c

Please sign in to comment.