summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGarrett Regier <garrettregier@gmail.com>2015-01-22 18:54:11 -0800
committerGarrett Regier <garrettregier@gmail.com>2015-02-14 12:23:40 -0800
commit60cfc58eb64446fd3512f8c36b22a2f0b9968c9d (patch)
tree70b6bda4e251b04dcb35105d10ef7a56a784d3dd /tests
parentd2bed913817ef7bd9e018b3f63a36369aac74b9f (diff)
downloadlibpeas-60cfc58eb64446fd3512f8c36b22a2f0b9968c9d.tar.gz
Prevent the accidental escaping of globals with Lua plugins
This implements a strict mode which prevents the creation of globals, except when using rawset(). This can be disabled for incompatible code by setting __STRICT to false. https://bugzilla.gnome.org/show_bug.cgi?id=742557
Diffstat (limited to 'tests')
-rw-r--r--tests/libpeas/plugins/extension-lua/extension-lua51.lua21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/libpeas/plugins/extension-lua/extension-lua51.lua b/tests/libpeas/plugins/extension-lua/extension-lua51.lua
index a0162fe..89cdf2d 100644
--- a/tests/libpeas/plugins/extension-lua/extension-lua51.lua
+++ b/tests/libpeas/plugins/extension-lua/extension-lua51.lua
@@ -80,6 +80,27 @@ function ExtensionLuaPlugin:do_call_multi_args(in_, inout)
return inout, in_
end
+-- Test strict mode
+local UNIQUE = {}
+
+local function assert_error(success, result)
+ assert(not success, result)
+end
+
+assert_error(pcall(function() _G[UNIQUE] = true end))
+assert(pcall(function()
+ rawset(_G, UNIQUE, true)
+ assert(_G[UNIQUE] == true)
+ _G[UNIQUE] = nil
+end))
+assert_error(pcall(function() _G[UNIQUE] = true end))
+assert(pcall(function()
+ __STRICT = false
+ _G[UNIQUE] = true
+ _G[UNIQUE] = nil
+ __STRICT = true
+end))
+
return { ExtensionLuaPlugin }
-- ex:set ts=4 et sw=4 ai: