From 540fa9ca18c5f428306306074cb23894d40a0040 Mon Sep 17 00:00:00 2001 From: Patman64 Date: Mon, 11 Aug 2014 00:53:01 -0400 Subject: [PATCH] Fix possible panic in Eluna::ExecuteCall. The panic shouldn't actually be possible due to checks in the different Register functions, but more checks doesn't hurt. --- LuaEngine.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/LuaEngine.cpp b/LuaEngine.cpp index d735e0d..a6e3107 100644 --- a/LuaEngine.cpp +++ b/LuaEngine.cpp @@ -326,7 +326,15 @@ void Eluna::report(lua_State* L) void Eluna::ExecuteCall(lua_State* L, int params, int res) { int top = lua_gettop(L); - luaL_checktype(L, top - params, LUA_TFUNCTION); + int type = lua_type(L, top - params); + + if (type != LUA_TFUNCTION) + { + lua_pop(L, params + 1); // Cleanup the stack. + ELUNA_LOG_ERROR("[Eluna]: Cannot execute call: registered value is a %s, not a function.", lua_typename(L, type)); + return; + } + if (lua_pcall(L, params, res, 0)) report(L); }