]> git.ipfire.org Git - thirdparty/haproxy.git/commit
BUG/MINOR: hlua: don't use lua_tostring() from unprotected contexts
authorAurelien DARRAGON <adarragon@haproxy.com>
Fri, 1 Mar 2024 14:55:17 +0000 (15:55 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Mon, 4 Mar 2024 15:46:55 +0000 (16:46 +0100)
commit369bfa0b50396a496a03fad59844196a3287784e
tree1ffc81277e1cc368560cd47471b511ed1aa9afb4
parent5508db9a20d995804edccd48144292ab1b8d8b08
BUG/MINOR: hlua: don't use lua_tostring() from unprotected contexts

As per lua documentation, lua_tostring() may raise a memory error.
However, we're often using it to fetch the error message at the top of
the stack (ie: after a failing lua call) from unprotected environments.
In practise, lua_tostring() has rare chances of failing, but still, if
it happens to be the case, it could crash the process and we better not
risk it.

So here, we add hlua_tostring_safe() function, which works exactly as
lua_tostring(), but the function cannot LJMP as it will catch
lua_tostring() exceptions to return NULL instead.

Everywhere lua_tostring() was used to retrieve error string from such
unprotected contexts, we now rely on hlua_tostring_safe().

This should be backported to all stable versions.

[ada: ctx adj will be required, for versions prior to 2.8 event_hdl
 API didn't exist so some chunks won't apply, and prior to 2.5 filters
 API didn't exist either, so again, some chunks should be ignored]
src/hlua.c