BUG/MEDIUM: hlua: make hlua_ctx_renew() safe
authorAurelien DARRAGON <adarragon@haproxy.com>
Tue, 8 Oct 2024 09:34:10 +0000 (11:34 +0200)
committerChristopher Faulet <cfaulet@haproxy.com>
Wed, 23 Oct 2024 14:41:37 +0000 (16:41 +0200)
commitde48cdf1fc7aead886571aff5f7e824e253cb718
treef81589eed916084db22f9b65e11df2f2f72133a6
parent2529cbc926b23f3f8372bf06c3e827133cf6197c
BUG/MEDIUM: hlua: make hlua_ctx_renew() safe

hlua_ctx_renew() is called from unsafe places where the caller doesn't
expect it to LJMP.. however hlua_ctx_renew() makes use of Lua library
function that could potentially raise errors, such as lua_newthread(),
and it does nothing to catch errors. Because of this, haproxy could
unexpectedly crash. This was discovered and reported by GH user
@JB0925 on #2745.

To fix the issue, let's simply make hlua_ctx_renew() safe by applying
the same logic implemented for hlua_ctx_init() or hlua_ctx_destroy(),
which is catching Lua errors by leveraging SET_SAFE_LJMP_PARENT() helper.

It should be backported to all stable versions.

(cherry picked from commit d0e01051813bde5cb06bebe88102f2b2885b3dea)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
src/hlua.c