-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #245 from GinjaNinja32/sandbox-metatable
Improve sandboxing setup; re-allow get/setmetatable
- Loading branch information
Showing
5 changed files
with
124 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include "lua/lua.hpp" | ||
#include "scriptInterfaceSandbox.h" | ||
|
||
// Add or protect a metatable for the provided object | ||
// Input Lua stack: [object] | ||
// Output Lua stack: [object] | ||
void protectLuaMetatable(lua_State* L) | ||
{ | ||
if (!lua_getmetatable(L, -1)) { | ||
lua_newtable(L); // [object] [mt] | ||
lua_pushvalue(L, -1); // [object] [mt] [mt] | ||
lua_setmetatable(L, -3); // [object] [mt] | ||
} | ||
|
||
lua_pushstring(L, "__metatable"); // [object] [mt] "__metatable" | ||
lua_pushstring(L, "sandbox"); // [object] [mt] "__metatable" "sandbox" | ||
lua_rawset(L, -3); // [object] [mt] | ||
lua_pop(L, 1); // [object] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef SCRIPT_INTERFACE_SANDBOX_H | ||
#define SCRIPT_INTERFACE_SANDBOX_H | ||
|
||
#include "lua/lua.hpp" | ||
|
||
// Add or protect a metatable for the provided object such that the metatable can't be read or changed from inside the sandbox. | ||
// Input Lua stack: [object] | ||
// Output Lua stack: [object] | ||
void protectLuaMetatable(lua_State* L); | ||
|
||
#endif // SCRIPT_INTERFACE_SANDBOX_H |