BUG/MEDIUM: lua: Always init the lua stack before referencing the context

When a lua context is allocated, its stack must be initialized to NULL
before attaching it to its owner (task, stream or applet).  Otherwise, if
the watchdog is fired before the stack is really created, that may lead to a
segfault because we try to dump the traceback of an uninitialized lua stack.

It is easy to trigger this bug if a lua script do a blocking call while
another thread try to initialize a new lua context. Because of the global
lua lock, the init is blocked before the stack creation. Of course, it only
happens if the script is executed in the shared global context.

This patch must be backported as far as 2.0.

(cherry picked from commit 1e8433f594de4b860e5205fdd6cb40d91ff58f17)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit f2e7362e0cf879b3c78b29d3d8406a28668c1e12)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 36cdbeed01a1106c6e1c8efd4f1161721bc51212)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
1 file changed