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]

(cherry picked from commit 369bfa0b50396a496a03fad59844196a3287784e)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit 14f472a5fc5e3f0944957f4d27b1311cdf05e8c2)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit cf51189d41e0dd10ccc87af7a049d4475c5b70e5)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit fbc9c86193a4c5ea5db22ded8b068a86fcaa6ed5)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
(cherry picked from commit daffc957ca67a78360bb23a937f19a72e86f8cd3)
Signed-off-by: Christopher Faulet <cfaulet@haproxy.com>
1 file changed