summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ldblib.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/ldblib.c b/ldblib.c
index c0226945..f71e1fdd 100644
--- a/ldblib.c
+++ b/ldblib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldblib.c,v 1.132 2012/01/19 20:14:44 roberto Exp $ 2** $Id: ldblib.c,v 1.132.1.1 2013/04/12 18:48:47 roberto Exp roberto $
3** Interface from Lua to its debug API 3** Interface from Lua to its debug API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -21,6 +21,11 @@
21#define HOOKKEY "_HKEY" 21#define HOOKKEY "_HKEY"
22 22
23 23
24static void checkstack (lua_State *L, lua_State *L1, int n) {
25 if (L != L1 && !lua_checkstack(L1, n))
26 luaL_error(L, "stack overflow");
27}
28
24 29
25static int db_getregistry (lua_State *L) { 30static int db_getregistry (lua_State *L) {
26 lua_pushvalue(L, LUA_REGISTRYINDEX); 31 lua_pushvalue(L, LUA_REGISTRYINDEX);
@@ -114,6 +119,7 @@ static int db_getinfo (lua_State *L) {
114 int arg; 119 int arg;
115 lua_State *L1 = getthread(L, &arg); 120 lua_State *L1 = getthread(L, &arg);
116 const char *options = luaL_optstring(L, arg+2, "flnStu"); 121 const char *options = luaL_optstring(L, arg+2, "flnStu");
122 checkstack(L, L1, 3);
117 if (lua_isnumber(L, arg+1)) { 123 if (lua_isnumber(L, arg+1)) {
118 if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)) { 124 if (!lua_getstack(L1, (int)lua_tointeger(L, arg+1), &ar)) {
119 lua_pushnil(L); /* level out of range */ 125 lua_pushnil(L); /* level out of range */
@@ -173,6 +179,7 @@ static int db_getlocal (lua_State *L) {
173 else { /* stack-level argument */ 179 else { /* stack-level argument */
174 if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */ 180 if (!lua_getstack(L1, luaL_checkint(L, arg+1), &ar)) /* out of range? */
175 return luaL_argerror(L, arg+1, "level out of range"); 181 return luaL_argerror(L, arg+1, "level out of range");
182 checkstack(L, L1, 1);
176 name = lua_getlocal(L1, &ar, nvar); 183 name = lua_getlocal(L1, &ar, nvar);
177 if (name) { 184 if (name) {
178 lua_xmove(L1, L, 1); /* push local value */ 185 lua_xmove(L1, L, 1); /* push local value */
@@ -196,6 +203,7 @@ static int db_setlocal (lua_State *L) {
196 return luaL_argerror(L, arg+1, "level out of range"); 203 return luaL_argerror(L, arg+1, "level out of range");
197 luaL_checkany(L, arg+3); 204 luaL_checkany(L, arg+3);
198 lua_settop(L, arg+3); 205 lua_settop(L, arg+3);
206 checkstack(L, L1, 1);
199 lua_xmove(L, L1, 1); 207 lua_xmove(L, L1, 1);
200 lua_pushstring(L, lua_setlocal(L1, &ar, luaL_checkint(L, arg+2))); 208 lua_pushstring(L, lua_setlocal(L1, &ar, luaL_checkint(L, arg+2)));
201 return 1; 209 return 1;
@@ -313,6 +321,7 @@ static int db_sethook (lua_State *L) {
313 lua_pushvalue(L, -1); 321 lua_pushvalue(L, -1);
314 lua_setmetatable(L, -2); /* setmetatable(hooktable) = hooktable */ 322 lua_setmetatable(L, -2); /* setmetatable(hooktable) = hooktable */
315 } 323 }
324 checkstack(L, L1, 1);
316 lua_pushthread(L1); lua_xmove(L1, L, 1); 325 lua_pushthread(L1); lua_xmove(L1, L, 1);
317 lua_pushvalue(L, arg+1); 326 lua_pushvalue(L, arg+1);
318 lua_rawset(L, -3); /* set new hook */ 327 lua_rawset(L, -3); /* set new hook */
@@ -331,6 +340,7 @@ static int db_gethook (lua_State *L) {
331 lua_pushliteral(L, "external hook"); 340 lua_pushliteral(L, "external hook");
332 else { 341 else {
333 gethooktable(L); 342 gethooktable(L);
343 checkstack(L, L1, 1);
334 lua_pushthread(L1); lua_xmove(L1, L, 1); 344 lua_pushthread(L1); lua_xmove(L1, L, 1);
335 lua_rawget(L, -2); /* get hook */ 345 lua_rawget(L, -2); /* get hook */
336 lua_remove(L, -2); /* remove hook table */ 346 lua_remove(L, -2); /* remove hook table */