[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: setfenv, how to...
- From: "Leandro Candido" <enclle@...>
- Date: Fri, 14 Nov 2003 11:18:16 -0200
Thanx Kevin and Pedro by trying to solve my problem, but a "working"
(temporally) solution is in setfenv.lua, file attached.
The problem was after adding functions to the "protected" global, for
-- block code
I = 123;
tab.addGlobalVarI = addGlobalVarI;
-- end of block
Well, adding this function in tab without setfenv'ing it to tab
(protecting), has 2 secure problems: 1) the function will set I in the old
global table, and 2) a function inside tab can call getfenv to it and, well,
then will have the real global table, and can add anything to it, breaking
the protection. This is true to any function added to tab.
But, if I setfenv it, then if this function is inside other
"enviromments", the I will be written inside the wrong one. What's the best?
At momment, in runtime, inside lua, the best is to use wrapper functions,
who do nothing more than prior to call the real function, setfenv to his
global table, call the function, and than restore the enviromment to its
Someone has a better way/idea? Or comments? See the code to test this in
setfenv.lua. The file is incomplete.
Beware that this code is to making things without loading or dofile'ing
Description: Binary data