0003-BUG-MINOR-lua-executes-the-function-destroying-the-L.patch 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. From 49d319a677432b69c6a69ef5331ae2ed592075c9 Mon Sep 17 00:00:00 2001
  2. From: Thierry FOURNIER <thierry.fournier@ozon.io>
  3. Date: Wed, 12 Jul 2017 13:41:33 +0200
  4. Subject: [PATCH 03/18] BUG/MINOR: lua: executes the function destroying the
  5. Lua session in safe mode
  6. When we destroy the Lua session, we manipulates Lua stack,
  7. so errors can raises. It will be better to catch these errors.
  8. This patch should be backported in 1.6 and 1.7
  9. (cherry picked from commit 75d0208009c3189b5d10793e08f27dd62a76c3ae)
  10. Signed-off-by: Willy Tarreau <w@1wt.eu>
  11. ---
  12. src/hlua.c | 17 +++++++++++++++--
  13. 1 file changed, 15 insertions(+), 2 deletions(-)
  14. diff --git a/src/hlua.c b/src/hlua.c
  15. index 4c1c2d21..2d312804 100644
  16. --- a/src/hlua.c
  17. +++ b/src/hlua.c
  18. @@ -876,9 +876,15 @@ void hlua_ctx_destroy(struct hlua *lua)
  19. /* Purge all the pending signals. */
  20. hlua_com_purge(lua);
  21. + if (!SET_SAFE_LJMP(lua->T))
  22. + return;
  23. luaL_unref(lua->T, LUA_REGISTRYINDEX, lua->Mref);
  24. - luaL_unref(gL.T, LUA_REGISTRYINDEX, lua->Tref);
  25. + RESET_SAFE_LJMP(lua->T);
  26. + if (!SET_SAFE_LJMP(gL.T))
  27. + return;
  28. + luaL_unref(gL.T, LUA_REGISTRYINDEX, lua->Tref);
  29. + RESET_SAFE_LJMP(gL.T);
  30. /* Forces a garbage collecting process. If the Lua program is finished
  31. * without error, we run the GC on the thread pointer. Its freed all
  32. * the unused memory.
  33. @@ -889,9 +895,16 @@ void hlua_ctx_destroy(struct hlua *lua)
  34. * the garbage collection.
  35. */
  36. if (lua->flags & HLUA_MUST_GC) {
  37. + if (!SET_SAFE_LJMP(lua->T))
  38. + return;
  39. lua_gc(lua->T, LUA_GCCOLLECT, 0);
  40. - if (lua_status(lua->T) != LUA_OK)
  41. + RESET_SAFE_LJMP(lua->T);
  42. + if (lua_status(lua->T) != LUA_OK) {
  43. + if (!SET_SAFE_LJMP(gL.T))
  44. + return;
  45. lua_gc(gL.T, LUA_GCCOLLECT, 0);
  46. + RESET_SAFE_LJMP(gL.T);
  47. + }
  48. }
  49. lua->T = NULL;
  50. --
  51. 2.13.0