In hlua_filter_callback(), some lua stack work is performed under
SET_SAFE_LJMP() guard which also takes care of locking the hlua context
when needed. However, a lua_gettop() call is performed out of the guard,
thus it is unsafe in multithreading context if the script is loaded using
'lua-load' because in this case the main lua stack is shared between
threads and each access to a lua stack must be performed under the lock,
thus we move lua_gettop() call under the lock.
It should be backported up to 2.6.
goto end;
if (!HLUA_IS_RUNNING(flt_hlua)) {
- int extra_idx = lua_gettop(flt_hlua->T);
+ int extra_idx;
/* The following Lua calls can fail. */
if (!SET_SAFE_LJMP(flt_hlua)) {
goto end;
}
+ extra_idx = lua_gettop(flt_hlua->T);
+
/* Check stack size. */
if (!lua_checkstack(flt_hlua->T, 3)) {
SEND_ERR(s->be, "Lua filter '%s': full stack.\n", conf->reg->name);