From efa162bcd7ab1477c07d8ee85537e27c0cb1524b Mon Sep 17 00:00:00 2001 From: meir Date: Tue, 15 Feb 2022 20:18:49 +0200 Subject: Protect any table which is reachable from globals and added globals white list. The white list is done by setting a metatable on the global table before initializing any library. The metatable set the `__newindex` field to a function that check the white list before adding the field to the table. Fields which is not on the white list are simply ignored. After initialization phase is done we protect the global table and each table that might be reachable from the global table. For each table we also protect the table metatable if exists. --- deps/lua/src/lapi.c | 8 ++++++++ deps/lua/src/lua.h | 1 + 2 files changed, 9 insertions(+) (limited to 'deps') diff --git a/deps/lua/src/lapi.c b/deps/lua/src/lapi.c index 1a9455629..e8ef41ea2 100644 --- a/deps/lua/src/lapi.c +++ b/deps/lua/src/lapi.c @@ -1099,3 +1099,11 @@ LUA_API void lua_enablereadonlytable (lua_State *L, int objindex, int enabled) { t->readonly = enabled; } +LUA_API int lua_isreadonlytable (lua_State *L, int objindex) { + const TValue* o = index2adr(L, objindex); + api_check(L, ttistable(o)); + Table* t = hvalue(o); + api_check(L, t != hvalue(registry(L))); + return t->readonly; +} + diff --git a/deps/lua/src/lua.h b/deps/lua/src/lua.h index e478d14c0..280ef2382 100644 --- a/deps/lua/src/lua.h +++ b/deps/lua/src/lua.h @@ -359,6 +359,7 @@ struct lua_Debug { }; LUA_API void lua_enablereadonlytable (lua_State *L, int index, int enabled); +LUA_API int lua_isreadonlytable (lua_State *L, int index); /* }====================================================================== */ -- cgit v1.2.1