summaryrefslogtreecommitdiff
path: root/ldblib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2008-01-21 11:37:08 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2008-01-21 11:37:08 -0200
commit74897bc52f07d416c717edeb1e26e75d62e937dd (patch)
tree432e68ea64be0a06030acae1cda90a6029b0f13b /ldblib.c
parente7c989baf16aee1f2b5ad52bc512c5c02d9d4048 (diff)
downloadlua-74897bc52f07d416c717edeb1e26e75d62e937dd.tar.gz
lua-74897bc52f07d416c717edeb1e26e75d62e937dd.tar.bz2
lua-74897bc52f07d416c717edeb1e26e75d62e937dd.zip
bug: debug.sethook/gethook may overflow thread's stack
Diffstat (limited to 'ldblib.c')
-rw-r--r--ldblib.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/ldblib.c b/ldblib.c
index a7ceca9c..7ac21a59 100644
--- a/ldblib.c
+++ b/ldblib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldblib.c,v 1.107 2007/06/22 15:33:54 roberto Exp roberto $ 2** $Id: ldblib.c,v 1.108 2008/01/18 17:14: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*/
@@ -268,13 +268,12 @@ static int db_sethook (lua_State *L) {
268 count = luaL_optint(L, arg+3, 0); 268 count = luaL_optint(L, arg+3, 0);
269 func = hookf; mask = makemask(smask, count); 269 func = hookf; mask = makemask(smask, count);
270 } 270 }
271 gethooktable(L1); 271 gethooktable(L);
272 lua_pushlightuserdata(L1, L1); 272 lua_pushlightuserdata(L, L1);
273 lua_pushvalue(L, arg+1); 273 lua_pushvalue(L, arg+1);
274 lua_xmove(L, L1, 1); 274 lua_rawset(L, -3); /* set new hook */
275 lua_rawset(L1, -3); /* set new hook */ 275 lua_pop(L, 1); /* remove hook table */
276 lua_pop(L1, 1); /* remove hook table */ 276 lua_sethook(L1, func, mask, count); /* set hooks */
277 lua_sethook(L1, func, mask, count);
278 return 0; 277 return 0;
279} 278}
280 279
@@ -288,11 +287,10 @@ static int db_gethook (lua_State *L) {
288 if (hook != NULL && hook != hookf) /* external hook? */ 287 if (hook != NULL && hook != hookf) /* external hook? */
289 lua_pushliteral(L, "external hook"); 288 lua_pushliteral(L, "external hook");
290 else { 289 else {
291 gethooktable(L1); 290 gethooktable(L);
292 lua_pushlightuserdata(L1, L1); 291 lua_pushlightuserdata(L, L1);
293 lua_rawget(L1, -2); /* get hook */ 292 lua_rawget(L, -2); /* get hook */
294 lua_remove(L1, -2); /* remove hook table */ 293 lua_remove(L, -2); /* remove hook table */
295 lua_xmove(L1, L, 1);
296 } 294 }
297 lua_pushstring(L, unmakemask(mask, buff)); 295 lua_pushstring(L, unmakemask(mask, buff));
298 lua_pushinteger(L, lua_gethookcount(L1)); 296 lua_pushinteger(L, lua_gethookcount(L1));