prosody: Make getfenv() replacement for require() sandboxing local to avoid polluting the globals table
authorKim Alvefur <zash@zash.se>
Mon, 13 Oct 2014 21:02:04 +0200
changeset 6473 67501b5576d3
parent 6471 3728c30da4e3
child 6476 7c8f58d2b331
prosody: Make getfenv() replacement for require() sandboxing local to avoid polluting the globals table
prosody
--- 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(...)