summaryrefslogtreecommitdiff
path: root/src/script_lua.h
diff options
context:
space:
mode:
authormeir <meir@redis.com>2022-02-06 17:41:55 +0200
committermeir <meir@redis.com>2022-04-27 00:37:40 +0300
commit3731580b6b80c586322cadc6bc4be2b8b2bbb206 (patch)
tree7f50c1c866326f6e27495492b5abc61a4087a47c /src/script_lua.h
parent992f9e23c7ee819ad0dfac0bd6224d8330366960 (diff)
downloadredis-3731580b6b80c586322cadc6bc4be2b8b2bbb206.tar.gz
Protect globals of both evals scripts and functions.
Use the new `lua_enablereadonlytable` Lua API to protect the global tables of both evals scripts and functions. For eval scripts, the implemetation is easy, We simply call `lua_enablereadonlytable` on the global table to turn it into a readonly table. On functions its more complecated, we want to be able to switch globals between load run and function run. To achieve this, we create a new empty table that acts as the globals table for function, we control the actual globals using metatable manipulation. Notice that even if the user gets a pointer to the original tables, all the tables are set to be readonly (using `lua_enablereadonlytable` Lua API) so he can not change them. The following inlustration better explain the solution: ``` Global table {} <- global table metatable {.__index = __real_globals__} ``` The `__real_globals__` is set depends on the run context (function load or function call). Why this solution is needed and its not enough to simply switch globals? When we run in the context of function load and create our functions, our function gets the current globals that was set when they were created. Replacing the globals after the creation will not effect them. This is why this trick it mandatory.
Diffstat (limited to 'src/script_lua.h')
-rw-r--r--src/script_lua.h1
1 files changed, 0 insertions, 1 deletions
diff --git a/src/script_lua.h b/src/script_lua.h
index f39c01744..e6ca4f730 100644
--- a/src/script_lua.h
+++ b/src/script_lua.h
@@ -67,7 +67,6 @@ typedef struct errorInfo {
void luaRegisterRedisAPI(lua_State* lua);
sds luaGetStringSds(lua_State *lua, int index);
-void luaEnableGlobalsProtection(lua_State *lua);
void luaRegisterGlobalProtectionFunction(lua_State *lua);
void luaSetGlobalProtection(lua_State *lua);
void luaRegisterLogFunction(lua_State* lua);