From: Christof Lauber Date: Wed, 25 Apr 2018 06:57:39 +0000 (+0200) Subject: pbx_lua: Support displaying lua error message if no debug table exists X-Git-Tag: 16.0.0-rc1~157^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9c9f314f64c1add58d2976a1d9ec1b54b09ce7e4;p=thirdparty%2Fasterisk.git pbx_lua: Support displaying lua error message if no debug table exists The lua_error_function assumed that lua's debug table and traceback function are always accessible, which is not the case. This fixes the error message 'Error in the lua error handler' triggred by switch exec() function. If this happens lua's error message is shown without traceback. Change-Id: I34ba0a098f1ae06a3af7b4d1b098bd43f42f96c8 --- diff --git a/pbx/pbx_lua.c b/pbx/pbx_lua.c index 741e9507db..8673dfdef5 100644 --- a/pbx/pbx_lua.c +++ b/pbx/pbx_lua.c @@ -805,7 +805,19 @@ static int lua_error_function(lua_State *L) lua_pushliteral(L, "\n"); lua_getglobal(L, "debug"); + if (!lua_istable(L, -1)) { + /* Have no 'debug' table for whatever reason */ + lua_pop(L, 2); + /* Original err message is on stack top now */ + return 1; + } lua_getfield(L, -1, "traceback"); + if (!lua_isfunction(L, -1)) { + /* Same here for traceback function */ + lua_pop(L, 3); + /* Original err message is on stack top now */ + return 1; + } lua_remove(L, -2); /* remove the 'debug' table */ lua_pushvalue(L, message_index);