Changeset

6470:67501b5576d3

prosody: Make getfenv() replacement for require() sandboxing local to avoid polluting the globals table
author Kim Alvefur <zash@zash.se>
date Mon, 13 Oct 2014 21:02:04 +0200
parents 6468:3728c30da4e3
children 6473:7c8f58d2b331
files prosody
diffstat 1 files changed, 4 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/prosody	Wed Oct 08 18:42:33 2014 -0400
+++ b/prosody	Mon Oct 13 21:02:04 2014 +0200
@@ -151,13 +151,11 @@
 	-- for neat sandboxing of modules
 	local _realG = _G;
 	local _real_require = require;
-	if not getfenv then
+	local getfenv = getfenv or function (f)
 		-- FIXME: This is a hack to replace getfenv() in Lua 5.2
-		function getfenv(f)
-			local name, env = debug.getupvalue(debug.getinfo(f or 1).func, 1);
-			if name == "_ENV" then
-				return env;
-			end
+		local name, env = debug.getupvalue(debug.getinfo(f or 1).func, 1);
+		if name == "_ENV" then
+			return env;
 		end
 	end
 	function require(...)