# HG changeset patch # User Matthew Wild # Date 1327280655 0 # Node ID 15fe442e70c5865ba1ec21926a60ea1701ebe57a # Parent e6e5c76ff00916736a808ca5ed39badb4ecc153a prosody: sandboxed require(): Point __index of _G at current env for modules that need to reference globals they already set diff -r e6e5c76ff009 -r 15fe442e70c5 prosody --- a/prosody Mon Jan 23 00:56:57 2012 +0000 +++ b/prosody Mon Jan 23 01:04:15 2012 +0000 @@ -150,10 +150,14 @@ local curr_env_mt = getmetatable(getfenv(2)); local _realG_mt = getmetatable(_realG); if curr_env_mt and curr_env_mt.__index and not curr_env_mt.__newindex and _realG_mt then - local old_newindex + local old_newindex, old_index; old_newindex, _realG_mt.__newindex = _realG_mt.__newindex, curr_env; + old_index, _realG_mt.__index = _realG_mt.__index, function (_G, k) + return rawget(curr_env, k); + end; local ret = _real_require(...); _realG_mt.__newindex = old_newindex; + _realG_mt.__index = old_index; return ret; end return _real_require(...);