lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hello,

    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
example:
    -- block code
    function addGlobalVarI()
            I = 123;
            print(I);
    end

    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
original.

    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
anything.

                                                                    The
God's Peace,


Leandro.

Attachment: setfenv.lua
Description: Binary data