diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2007-02-09 10:40:21 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2007-02-09 10:40:21 -0200 |
commit | d3c304e92e5581bb7b8b7c5a61beb0a6faa108c2 (patch) | |
tree | e5bad55c3b3d758d95e18ac96f181f5b49b81785 | |
parent | 3bf0292cd5949d05b42ad474ca00d1c004ee9471 (diff) | |
download | lua-d3c304e92e5581bb7b8b7c5a61beb0a6faa108c2.tar.gz lua-d3c304e92e5581bb7b8b7c5a61beb0a6faa108c2.tar.bz2 lua-d3c304e92e5581bb7b8b7c5a61beb0a6faa108c2.zip |
BUG: setfenv accepts invalid argument
-rw-r--r-- | lbaselib.c | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.195 2006/10/24 19:46:12 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.196 2007/02/07 17:51:21 roberto Exp roberto $ |
3 | ** Basic library | 3 | ** Basic library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -114,11 +114,11 @@ static int luaB_setmetatable (lua_State *L) { | |||
114 | } | 114 | } |
115 | 115 | ||
116 | 116 | ||
117 | static void getfunc (lua_State *L) { | 117 | static void getfunc (lua_State *L, int opt) { |
118 | if (lua_isfunction(L, 1)) lua_pushvalue(L, 1); | 118 | if (lua_isfunction(L, 1)) lua_pushvalue(L, 1); |
119 | else { | 119 | else { |
120 | lua_Debug ar; | 120 | lua_Debug ar; |
121 | int level = luaL_optint(L, 1, 1); | 121 | int level = opt ? luaL_optint(L, 1, 1) : luaL_checkint(L, 1); |
122 | luaL_argcheck(L, level >= 0, 1, "level must be non-negative"); | 122 | luaL_argcheck(L, level >= 0, 1, "level must be non-negative"); |
123 | if (lua_getstack(L, level, &ar) == 0) | 123 | if (lua_getstack(L, level, &ar) == 0) |
124 | luaL_argerror(L, 1, "invalid level"); | 124 | luaL_argerror(L, 1, "invalid level"); |
@@ -131,7 +131,7 @@ static void getfunc (lua_State *L) { | |||
131 | 131 | ||
132 | 132 | ||
133 | static int luaB_getfenv (lua_State *L) { | 133 | static int luaB_getfenv (lua_State *L) { |
134 | getfunc(L); | 134 | getfunc(L, 1); |
135 | if (lua_iscfunction(L, -1)) /* is a C function? */ | 135 | if (lua_iscfunction(L, -1)) /* is a C function? */ |
136 | lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the thread's global env. */ | 136 | lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the thread's global env. */ |
137 | else | 137 | else |
@@ -142,7 +142,7 @@ static int luaB_getfenv (lua_State *L) { | |||
142 | 142 | ||
143 | static int luaB_setfenv (lua_State *L) { | 143 | static int luaB_setfenv (lua_State *L) { |
144 | luaL_checktype(L, 2, LUA_TTABLE); | 144 | luaL_checktype(L, 2, LUA_TTABLE); |
145 | getfunc(L); | 145 | getfunc(L, 0); |
146 | lua_pushvalue(L, 2); | 146 | lua_pushvalue(L, 2); |
147 | if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) { | 147 | if (lua_isnumber(L, 1) && lua_tonumber(L, 1) == 0) { |
148 | /* change environment of current thread */ | 148 | /* change environment of current thread */ |