[grilo-plugins] lua-factory: make grl and grl.lua read-only
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [grilo-plugins] lua-factory: make grl and grl.lua read-only
- Date: Mon, 21 Mar 2016 22:57:41 +0000 (UTC)
commit 3b61064b7b2284667d12015ac40c031e76abd43f
Author: Victor Toso <me victortoso com>
Date: Mon Mar 21 16:47:44 2016 +0100
lua-factory: make grl and grl.lua read-only
By using the metamethod __new_index to trigger an error in case Lua
source try to use it.
https://bugzilla.gnome.org/show_bug.cgi?id=763046
src/lua-factory/grl-lua-library-operations.c | 13 ++++++++++++-
src/lua-factory/grl-lua-library.c | 2 ++
2 files changed, 14 insertions(+), 1 deletions(-)
---
diff --git a/src/lua-factory/grl-lua-library-operations.c b/src/lua-factory/grl-lua-library-operations.c
index 47e256b..0fa6a9d 100644
--- a/src/lua-factory/grl-lua-library-operations.c
+++ b/src/lua-factory/grl-lua-library-operations.c
@@ -102,6 +102,17 @@ proxy_metatable_handle_call (lua_State *L)
return 0;
}
+/*
+ * proxy handler for __newindex metamethod
+ * This metamethod is called when updating a table with a new key/value.
+ */
+static int
+proxy_metatable_handle_newindex (lua_State *L)
+{
+ luaL_error (L, "Trying to change read-only table");
+ return 0;
+}
+
/* ============== Private State helpers ==================================== */
/*
@@ -626,7 +637,7 @@ grl_lua_operations_set_proxy_table (lua_State *L,
/* __newindex: triggered when inserting new key/value to given table */
lua_pushstring (L, "__newindex");
- lua_pushvalue (L, index - 3);
+ lua_pushcfunction (L, proxy_metatable_handle_newindex);
lua_settable (L, -3);
/* __call: triggered when using the table as a function */
diff --git a/src/lua-factory/grl-lua-library.c b/src/lua-factory/grl-lua-library.c
index b5345af..1952f15 100644
--- a/src/lua-factory/grl-lua-library.c
+++ b/src/lua-factory/grl-lua-library.c
@@ -1653,6 +1653,7 @@ luaopen_grilo (lua_State *L)
}
lua_pop (L, 1);
+ /* grl.lua will be read-only from now on for Lua sources */
grl_lua_operations_set_proxy_table (L, -1);
/* Those modules are called in 'lua' table, inside 'grl' */
@@ -1660,6 +1661,7 @@ luaopen_grilo (lua_State *L)
grl_lua_operations_init_priv_state (L);
+ /* grl will be read-only from now on for Lua sources */
grl_lua_operations_set_proxy_table (L, -1);
return 1;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]