The following assumes you can compile the Lua code yourself in the required DLL. It adds a simple time check to stop infinite loops and other malicious Lua code.
The changes should be obvious. Starts at line 374 in lvm.c
As always, Your Mileage May Vary
The changes should be obvious. Starts at line 374 in lvm.c
void luaV_execute (lua_State *L, int nexeccalls) {
LClosure *cl;
StkId base;
TValue *k;
const Instruction *pc;
int origClock = (clock() / CLOCKS_PER_SEC); // <--add start
int runtClock = 0; // <--add stop
reentry: /* entry point */
lua_assert(isLua(L->ci));
pc = L->savedpc;
cl = &clvalue(L->ci->func)->l;
base = L->base;
k = cl->p->k;
/* main loop of interpreter */
for (;;) {
const Instruction i = *pc++;
StkId ra;
runtClock = (clock() / CLOCKS_PER_SEC) - origClock; // <--add start
if( runtClock > 2 ) {
luaG_runerror(L, "Runtime length of 2 seconds exceeded.");
} // <--add stop
if ((L->hookmask & (LUA_MASKLINE | LUA_MASKCOUNT)) &&
(--L->hookcount == 0 || L->hookmask & LUA_MASKLINE)) {
traceexec(L, pc);
As always, Your Mileage May Vary