From e344b2b5879aa52870e6838212dfb78b7968fcbf Mon Sep 17 00:00:00 2001
From: YaacovHazan <yaacov.hazan@redis.com>
Date: Sun, 15 Dec 2024 21:33:11 +0200
Subject: [PATCH] Fix LUA garbage collector (CVE-2024-46981) 

Reset GC state before closing the lua VM to prevent user data 
to be wrongly freed while still might be used on destructor callbacks.

CVE: CVE-2024-46981

Upstream-Status: Backport [https://github.com/redis/redis/commit/e344b2b5879aa52870e6838212dfb78b7968fcbf]

Signed-off-by: Divya Chellam <divya.chellam@windriver.com>
---
 src/eval.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/eval.c b/src/eval.c
index 8190856..a562335 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -273,6 +273,7 @@ void scriptingRelease(int async) {
     else
         dictRelease(lctx.lua_scripts);
     lctx.lua_scripts_mem = 0;
+    lua_gc(lctx.lua, LUA_GCCOLLECT, 0);
     lua_close(lctx.lua);
 }
 
-- 
2.40.0

