summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-02-19 15:05:13 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-02-19 15:05:13 -0200
commitabd8f8433dc6628add06b1aa3568d40c1fdd9c46 (patch)
treeab803d7df4d59d90224b666662e5a9749b8a4754
parentce74637ace147d147578a95c435cf7cafec590b8 (diff)
downloadlua-abd8f8433dc6628add06b1aa3568d40c1fdd9c46.tar.gz
lua-abd8f8433dc6628add06b1aa3568d40c1fdd9c46.tar.bz2
lua-abd8f8433dc6628add06b1aa3568d40c1fdd9c46.zip
bug: suspended function can have its 'func' field not pointing to
its function, crashing debug functions
-rw-r--r--ldebug.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/ldebug.c b/ldebug.c
index a585075c..d9962b98 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 2.90.1.2 2013/05/06 17:20:22 roberto Exp roberto $ 2** $Id: ldebug.c,v 2.90.1.3 2013/05/16 16:04:15 roberto Exp roberto $
3** Debug Interface 3** Debug Interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -47,6 +47,16 @@ static int currentline (CallInfo *ci) {
47} 47}
48 48
49 49
50static void swapextra (lua_State *L) {
51 if (L->status == LUA_YIELD) {
52 CallInfo *ci = L->ci; /* get function that yielded */
53 StkId temp = ci->func; /* exchange its 'func' and 'extra' values */
54 ci->func = restorestack(L, ci->extra);
55 ci->extra = savestack(L, temp);
56 }
57}
58
59
50/* 60/*
51** this function can be called asynchronous (e.g. during a signal) 61** this function can be called asynchronous (e.g. during a signal)
52*/ 62*/
@@ -144,6 +154,7 @@ static const char *findlocal (lua_State *L, CallInfo *ci, int n,
144LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) { 154LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
145 const char *name; 155 const char *name;
146 lua_lock(L); 156 lua_lock(L);
157 swapextra(L);
147 if (ar == NULL) { /* information about non-active function? */ 158 if (ar == NULL) { /* information about non-active function? */
148 if (!isLfunction(L->top - 1)) /* not a Lua function? */ 159 if (!isLfunction(L->top - 1)) /* not a Lua function? */
149 name = NULL; 160 name = NULL;
@@ -158,6 +169,7 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
158 api_incr_top(L); 169 api_incr_top(L);
159 } 170 }
160 } 171 }
172 swapextra(L);
161 lua_unlock(L); 173 lua_unlock(L);
162 return name; 174 return name;
163} 175}
@@ -165,11 +177,14 @@ LUA_API const char *lua_getlocal (lua_State *L, const lua_Debug *ar, int n) {
165 177
166LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) { 178LUA_API const char *lua_setlocal (lua_State *L, const lua_Debug *ar, int n) {
167 StkId pos = 0; /* to avoid warnings */ 179 StkId pos = 0; /* to avoid warnings */
168 const char *name = findlocal(L, ar->i_ci, n, &pos); 180 const char *name;
169 lua_lock(L); 181 lua_lock(L);
182 swapextra(L);
183 name = findlocal(L, ar->i_ci, n, &pos);
170 if (name) 184 if (name)
171 setobjs2s(L, pos, L->top - 1); 185 setobjs2s(L, pos, L->top - 1);
172 L->top--; /* pop value */ 186 L->top--; /* pop value */
187 swapextra(L);
173 lua_unlock(L); 188 lua_unlock(L);
174 return name; 189 return name;
175} 190}
@@ -269,6 +284,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
269 CallInfo *ci; 284 CallInfo *ci;
270 StkId func; 285 StkId func;
271 lua_lock(L); 286 lua_lock(L);
287 swapextra(L);
272 if (*what == '>') { 288 if (*what == '>') {
273 ci = NULL; 289 ci = NULL;
274 func = L->top - 1; 290 func = L->top - 1;
@@ -287,6 +303,7 @@ LUA_API int lua_getinfo (lua_State *L, const char *what, lua_Debug *ar) {
287 setobjs2s(L, L->top, func); 303 setobjs2s(L, L->top, func);
288 api_incr_top(L); 304 api_incr_top(L);
289 } 305 }
306 swapextra(L);
290 if (strchr(what, 'L')) 307 if (strchr(what, 'L'))
291 collectvalidlines(L, cl); 308 collectvalidlines(L, cl);
292 lua_unlock(L); 309 lua_unlock(L);