Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
700b863f
Commit
700b863f
authored
May 11, 2015
by
Ben Murphy
Committed by
antirez
Jun 03, 2015
Browse files
hide access to debug table
parent
5a1b22ad
Changes
1
Show whitespace changes
Inline
Side-by-side
src/scripting.c
View file @
700b863f
...
@@ -593,11 +593,12 @@ void scriptingEnableGlobalsProtection(lua_State *lua) {
...
@@ -593,11 +593,12 @@ void scriptingEnableGlobalsProtection(lua_State *lua) {
/* strict.lua from: http://metalua.luaforge.net/src/lib/strict.lua.html.
/* strict.lua from: http://metalua.luaforge.net/src/lib/strict.lua.html.
* Modified to be adapted to Redis. */
* Modified to be adapted to Redis. */
s
[
j
++
]
=
"local dbg=debug
\n
"
;
s
[
j
++
]
=
"local mt = {}
\n
"
;
s
[
j
++
]
=
"local mt = {}
\n
"
;
s
[
j
++
]
=
"setmetatable(_G, mt)
\n
"
;
s
[
j
++
]
=
"setmetatable(_G, mt)
\n
"
;
s
[
j
++
]
=
"mt.__newindex = function (t, n, v)
\n
"
;
s
[
j
++
]
=
"mt.__newindex = function (t, n, v)
\n
"
;
s
[
j
++
]
=
" if d
ebu
g.getinfo(2) then
\n
"
;
s
[
j
++
]
=
" if d
b
g.getinfo(2) then
\n
"
;
s
[
j
++
]
=
" local w = d
ebu
g.getinfo(2,
\"
S
\"
).what
\n
"
;
s
[
j
++
]
=
" local w = d
b
g.getinfo(2,
\"
S
\"
).what
\n
"
;
s
[
j
++
]
=
" if w ~=
\"
main
\"
and w ~=
\"
C
\"
then
\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
++
]
=
" error(
\"
Script attempted to create global variable '
\"
..tostring(n)..
\"
'
\"
, 2)
\n
"
;
s
[
j
++
]
=
" end
\n
"
;
s
[
j
++
]
=
" end
\n
"
;
...
@@ -605,11 +606,12 @@ void scriptingEnableGlobalsProtection(lua_State *lua) {
...
@@ -605,11 +606,12 @@ void scriptingEnableGlobalsProtection(lua_State *lua) {
s
[
j
++
]
=
" rawset(t, n, v)
\n
"
;
s
[
j
++
]
=
" rawset(t, n, v)
\n
"
;
s
[
j
++
]
=
"end
\n
"
;
s
[
j
++
]
=
"end
\n
"
;
s
[
j
++
]
=
"mt.__index = function (t, n)
\n
"
;
s
[
j
++
]
=
"mt.__index = function (t, n)
\n
"
;
s
[
j
++
]
=
" if d
ebu
g.getinfo(2) and d
ebu
g.getinfo(2,
\"
S
\"
).what ~=
\"
C
\"
then
\n
"
;
s
[
j
++
]
=
" if d
b
g.getinfo(2) and d
b
g.getinfo(2,
\"
S
\"
).what ~=
\"
C
\"
then
\n
"
;
s
[
j
++
]
=
" error(
\"
Script attempted to access unexisting global variable '
\"
..tostring(n)..
\"
'
\"
, 2)
\n
"
;
s
[
j
++
]
=
" error(
\"
Script attempted to access unexisting global variable '
\"
..tostring(n)..
\"
'
\"
, 2)
\n
"
;
s
[
j
++
]
=
" end
\n
"
;
s
[
j
++
]
=
" end
\n
"
;
s
[
j
++
]
=
" return rawget(t, n)
\n
"
;
s
[
j
++
]
=
" return rawget(t, n)
\n
"
;
s
[
j
++
]
=
"end
\n
"
;
s
[
j
++
]
=
"end
\n
"
;
s
[
j
++
]
=
"debug = nil
\n
"
;
s
[
j
++
]
=
NULL
;
s
[
j
++
]
=
NULL
;
for
(
j
=
0
;
s
[
j
]
!=
NULL
;
j
++
)
code
=
sdscatlen
(
code
,
s
[
j
],
strlen
(
s
[
j
]));
for
(
j
=
0
;
s
[
j
]
!=
NULL
;
j
++
)
code
=
sdscatlen
(
code
,
s
[
j
],
strlen
(
s
[
j
]));
...
@@ -713,10 +715,11 @@ void scriptingInit(void) {
...
@@ -713,10 +715,11 @@ void scriptingInit(void) {
* information about the caller, that's what makes sense from the point
* information about the caller, that's what makes sense from the point
* of view of the user debugging a script. */
* of view of the user debugging a script. */
{
{
char
*
errh_func
=
"function __redis__err__handler(err)
\n
"
char
*
errh_func
=
"local dbg = debug
\n
"
" local i = debug.getinfo(2,'nSl')
\n
"
"function __redis__err__handler(err)
\n
"
" local i = dbg.getinfo(2,'nSl')
\n
"
" if i and i.what == 'C' then
\n
"
" if i and i.what == 'C' then
\n
"
" i = d
ebu
g.getinfo(3,'nSl')
\n
"
" i = d
b
g.getinfo(3,'nSl')
\n
"
" end
\n
"
" end
\n
"
" if i then
\n
"
" if i then
\n
"
" return i.source .. ':' .. i.currentline .. ': ' .. err
\n
"
" return i.source .. ':' .. i.currentline .. ': ' .. err
\n
"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment