diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-11-27 13:37:59 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-11-27 13:37:59 -0200 |
| commit | 3e41afcec550e8c5c3c4372f72efa48cbf7031a3 (patch) | |
| tree | 7ae0d003a8ba00b87aecebddc14ffd789a5a9b90 | |
| parent | 3acf5ec5a18c83ed0ce7e41c9b5789bddd2b3e60 (diff) | |
| download | lua-3e41afcec550e8c5c3c4372f72efa48cbf7031a3.tar.gz lua-3e41afcec550e8c5c3c4372f72efa48cbf7031a3.tar.bz2 lua-3e41afcec550e8c5c3c4372f72efa48cbf7031a3.zip | |
extra api checks for number of returns of C functions and for lua_yield
| -rw-r--r-- | lapi.c | 5 | ||||
| -rw-r--r-- | lapi.h | 5 | ||||
| -rw-r--r-- | ldo.c | 6 |
3 files changed, 10 insertions, 6 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 2.99 2009/11/09 18:55:17 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.100 2009/11/09 19:10:48 roberto Exp roberto $ |
| 3 | ** Lua API | 3 | ** Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -35,9 +35,6 @@ const char lua_ident[] = | |||
| 35 | 35 | ||
| 36 | 36 | ||
| 37 | 37 | ||
| 38 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ | ||
| 39 | "not enough elements in the stack") | ||
| 40 | |||
| 41 | #define api_checkvalidindex(L, i) api_check(L, (i) != luaO_nilobject, \ | 38 | #define api_checkvalidindex(L, i) api_check(L, (i) != luaO_nilobject, \ |
| 42 | "invalid index") | 39 | "invalid index") |
| 43 | 40 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.h,v 2.5 2009/04/03 15:58:03 roberto Exp roberto $ | 2 | ** $Id: lapi.h,v 2.6 2009/08/31 14:26:28 roberto Exp roberto $ |
| 3 | ** Auxiliary functions from Lua API | 3 | ** Auxiliary functions from Lua API |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -17,5 +17,8 @@ | |||
| 17 | #define adjustresults(L,nres) \ | 17 | #define adjustresults(L,nres) \ |
| 18 | { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } | 18 | { if ((nres) == LUA_MULTRET && L->ci->top < L->top) L->ci->top = L->top; } |
| 19 | 19 | ||
| 20 | #define api_checknelems(L,n) api_check(L, (n) < (L->top - L->ci->func), \ | ||
| 21 | "not enough elements in the stack") | ||
| 22 | |||
| 20 | 23 | ||
| 21 | #endif | 24 | #endif |
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: ldo.c,v 2.72 2009/11/17 16:46:44 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.73 2009/11/25 15:27:51 roberto Exp roberto $ |
| 3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -311,6 +311,7 @@ int luaD_precall (lua_State *L, StkId func, int nresults) { | |||
| 311 | lua_unlock(L); | 311 | lua_unlock(L); |
| 312 | n = (*curr_func(L)->c.f)(L); /* do the actual call */ | 312 | n = (*curr_func(L)->c.f)(L); /* do the actual call */ |
| 313 | lua_lock(L); | 313 | lua_lock(L); |
| 314 | api_checknelems(L, n); | ||
| 314 | luaD_poscall(L, L->top - n); | 315 | luaD_poscall(L, L->top - n); |
| 315 | return 1; | 316 | return 1; |
| 316 | } | 317 | } |
| @@ -382,6 +383,7 @@ static void finishCcall (lua_State *L) { | |||
| 382 | lua_unlock(L); | 383 | lua_unlock(L); |
| 383 | n = (*ci->u.c.k)(L); | 384 | n = (*ci->u.c.k)(L); |
| 384 | lua_lock(L); | 385 | lua_lock(L); |
| 386 | api_checknelems(L, n); | ||
| 385 | /* finish 'luaD_precall' */ | 387 | /* finish 'luaD_precall' */ |
| 386 | luaD_poscall(L, L->top - n); | 388 | luaD_poscall(L, L->top - n); |
| 387 | } | 389 | } |
| @@ -424,6 +426,7 @@ static void resume (lua_State *L, void *ud) { | |||
| 424 | lua_unlock(L); | 426 | lua_unlock(L); |
| 425 | n = (*ci->u.c.k)(L); /* call continuation */ | 427 | n = (*ci->u.c.k)(L); /* call continuation */ |
| 426 | lua_lock(L); | 428 | lua_lock(L); |
| 429 | api_checknelems(L, n); | ||
| 427 | firstArg = L->top - n; | 430 | firstArg = L->top - n; |
| 428 | } | 431 | } |
| 429 | G(L)->nCcalls--; /* finish 'luaD_call' */ | 432 | G(L)->nCcalls--; /* finish 'luaD_call' */ |
| @@ -511,6 +514,7 @@ LUA_API int lua_yieldk (lua_State *L, int nresults, int ctx, lua_CFunction k) { | |||
| 511 | CallInfo *ci = L->ci; | 514 | CallInfo *ci = L->ci; |
| 512 | luai_userstateyield(L, nresults); | 515 | luai_userstateyield(L, nresults); |
| 513 | lua_lock(L); | 516 | lua_lock(L); |
| 517 | api_checknelems(L, nresults); | ||
| 514 | if (L->nny > 0) | 518 | if (L->nny > 0) |
| 515 | luaG_runerror(L, "attempt to yield across metamethod/C-call boundary"); | 519 | luaG_runerror(L, "attempt to yield across metamethod/C-call boundary"); |
| 516 | L->status = LUA_YIELD; | 520 | L->status = LUA_YIELD; |
