summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Murphy <benmmurphy@gmail.com>2015-05-11 23:24:37 +0100
committerantirez <antirez@gmail.com>2015-06-03 13:33:28 +0200
commitffd6637e90d816b7a17a96f144f75153c952d8cf (patch)
tree40ebdd3b7d70467a92e933c661b80b55baebfef1
parentfdf9d455098f54f7666c702ae464e6ea21e25411 (diff)
downloadredis-ffd6637e90d816b7a17a96f144f75153c952d8cf.tar.gz
hide access to debug table
-rw-r--r--src/scripting.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/scripting.c b/src/scripting.c
index 4f807f4e2..53c0c9ed2 100644
--- a/src/scripting.c
+++ b/src/scripting.c
@@ -612,11 +612,12 @@ void scriptingEnableGlobalsProtection(lua_State *lua) {
/* strict.lua from: http://metalua.luaforge.net/src/lib/strict.lua.html.
* Modified to be adapted to Redis. */
+ s[j++]="local dbg=debug\n";
s[j++]="local mt = {}\n";
s[j++]="setmetatable(_G, mt)\n";
s[j++]="mt.__newindex = function (t, n, v)\n";
- s[j++]=" if debug.getinfo(2) then\n";
- s[j++]=" local w = debug.getinfo(2, \"S\").what\n";
+ s[j++]=" if dbg.getinfo(2) then\n";
+ s[j++]=" local w = dbg.getinfo(2, \"S\").what\n";
s[j++]=" if w ~= \"main\" and w ~= \"C\" then\n";
s[j++]=" error(\"Script attempted to create global variable '\"..tostring(n)..\"'\", 2)\n";
s[j++]=" end\n";
@@ -624,11 +625,12 @@ void scriptingEnableGlobalsProtection(lua_State *lua) {
s[j++]=" rawset(t, n, v)\n";
s[j++]="end\n";
s[j++]="mt.__index = function (t, n)\n";
- s[j++]=" if debug.getinfo(2) and debug.getinfo(2, \"S\").what ~= \"C\" then\n";
+ s[j++]=" if dbg.getinfo(2) and dbg.getinfo(2, \"S\").what ~= \"C\" then\n";
s[j++]=" error(\"Script attempted to access unexisting global variable '\"..tostring(n)..\"'\", 2)\n";
s[j++]=" end\n";
s[j++]=" return rawget(t, n)\n";
s[j++]="end\n";
+ s[j++]="debug = nil\n";
s[j++]=NULL;
for (j = 0; s[j] != NULL; j++) code = sdscatlen(code,s[j],strlen(s[j]));
@@ -732,10 +734,11 @@ void scriptingInit(void) {
* information about the caller, that's what makes sense from the point
* of view of the user debugging a script. */
{
- char *errh_func = "function __redis__err__handler(err)\n"
- " local i = debug.getinfo(2,'nSl')\n"
+ char *errh_func = "local dbg = debug\n"
+ "function __redis__err__handler(err)\n"
+ " local i = dbg.getinfo(2,'nSl')\n"
" if i and i.what == 'C' then\n"
- " i = debug.getinfo(3,'nSl')\n"
+ " i = dbg.getinfo(3,'nSl')\n"
" end\n"
" if i then\n"
" return i.source .. ':' .. i.currentline .. ': ' .. err\n"