diff --git a/Capy64/Runtime/Sandbox.cs b/Capy64/Runtime/Sandbox.cs index d540a12..87f2db1 100644 --- a/Capy64/Runtime/Sandbox.cs +++ b/Capy64/Runtime/Sandbox.cs @@ -37,6 +37,8 @@ internal class Sandbox L.OpenOS(); L.OpenPackage(); + + L.SetTop(0); } internal static void Patch(Lua L) { @@ -70,10 +72,11 @@ internal class Sandbox L.PushString("config"); L.PushString(packageConfig); L.SetTable(-4); + L.Pop(1); // delete 3 and 4 searchers L.PushString("searchers"); - L.GetTable(-3); + L.GetTable(-2); L.PushNil(); L.SetInteger(-2, 3); @@ -84,7 +87,7 @@ internal class Sandbox L.PushCFunction(L_Searcher); L.SetInteger(-2, 2); - L.Pop(L.GetTop()); + L.Pop(2); // Replace loadfile with sandboxed one L.PushCFunction(L_Loadfile); @@ -94,8 +97,6 @@ internal class Sandbox L.PushCFunction(L_Dofile); L.SetGlobal("dofile"); - L.Pop(L.GetTop()); - // yeet dangerous os functions L.GetGlobal("os"); @@ -118,6 +119,8 @@ internal class Sandbox L.PushString("getenv"); L.PushNil(); L.SetTable(-3); + + L.Pop(1); } internal static int L_Searcher(IntPtr state)