diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-02-11 16:47:22 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2015-02-11 16:47:22 -0200 |
| commit | 2e6e53c7ccb8634f21598b151413292c472ab432 (patch) | |
| tree | ddb8e9f4abbd2c3ae3111c63840c737af38d5d74 | |
| parent | 2a57d2346e2536b4ce954357a67c673c7ebe4adb (diff) | |
| download | lua-2e6e53c7ccb8634f21598b151413292c472ab432.tar.gz lua-2e6e53c7ccb8634f21598b151413292c472ab432.tar.bz2 lua-2e6e53c7ccb8634f21598b151413292c472ab432.zip | |
added API checks to some unprotected 'top' increments
| -rw-r--r-- | lapi.c | 19 |
1 files changed, 12 insertions, 7 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 2.244 2014/12/26 14:43:45 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.245 2015/01/16 16:54:37 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 | */ |
| @@ -124,7 +124,8 @@ LUA_API void lua_xmove (lua_State *from, lua_State *to, int n) { | |||
| 124 | api_check(to->ci->top - to->top >= n, "not enough elements to move"); | 124 | api_check(to->ci->top - to->top >= n, "not enough elements to move"); |
| 125 | from->top -= n; | 125 | from->top -= n; |
| 126 | for (i = 0; i < n; i++) { | 126 | for (i = 0; i < n; i++) { |
| 127 | setobj2s(to, to->top++, from->top + i); | 127 | setobj2s(to, to->top, from->top + i); |
| 128 | api_incr_top(to); | ||
| 128 | } | 129 | } |
| 129 | lua_unlock(to); | 130 | lua_unlock(to); |
| 130 | } | 131 | } |
| @@ -305,7 +306,7 @@ LUA_API void lua_arith (lua_State *L, int op) { | |||
| 305 | else { /* for unary operations, add fake 2nd operand */ | 306 | else { /* for unary operations, add fake 2nd operand */ |
| 306 | api_checknelems(L, 1); | 307 | api_checknelems(L, 1); |
| 307 | setobjs2s(L, L->top, L->top - 1); | 308 | setobjs2s(L, L->top, L->top - 1); |
| 308 | L->top++; | 309 | api_incr_top(L); |
| 309 | } | 310 | } |
| 310 | /* first operand at top - 2, second at top - 1; result go to top - 2 */ | 311 | /* first operand at top - 2, second at top - 1; result go to top - 2 */ |
| 311 | luaO_arith(L, op, L->top - 2, L->top - 1, L->top - 2); | 312 | luaO_arith(L, op, L->top - 2, L->top - 1, L->top - 2); |
| @@ -585,7 +586,8 @@ LUA_API int lua_getglobal (lua_State *L, const char *name) { | |||
| 585 | const TValue *gt; /* global table */ | 586 | const TValue *gt; /* global table */ |
| 586 | lua_lock(L); | 587 | lua_lock(L); |
| 587 | gt = luaH_getint(reg, LUA_RIDX_GLOBALS); | 588 | gt = luaH_getint(reg, LUA_RIDX_GLOBALS); |
| 588 | setsvalue2s(L, L->top++, luaS_new(L, name)); | 589 | setsvalue2s(L, L->top, luaS_new(L, name)); |
| 590 | api_incr_top(L); | ||
| 589 | luaV_gettable(L, gt, L->top - 1, L->top - 1); | 591 | luaV_gettable(L, gt, L->top - 1, L->top - 1); |
| 590 | lua_unlock(L); | 592 | lua_unlock(L); |
| 591 | return ttnov(L->top - 1); | 593 | return ttnov(L->top - 1); |
| @@ -726,7 +728,8 @@ LUA_API void lua_setglobal (lua_State *L, const char *name) { | |||
| 726 | lua_lock(L); | 728 | lua_lock(L); |
| 727 | api_checknelems(L, 1); | 729 | api_checknelems(L, 1); |
| 728 | gt = luaH_getint(reg, LUA_RIDX_GLOBALS); | 730 | gt = luaH_getint(reg, LUA_RIDX_GLOBALS); |
| 729 | setsvalue2s(L, L->top++, luaS_new(L, name)); | 731 | setsvalue2s(L, L->top, luaS_new(L, name)); |
| 732 | api_incr_top(L); | ||
| 730 | luaV_settable(L, gt, L->top - 1, L->top - 2); | 733 | luaV_settable(L, gt, L->top - 1, L->top - 2); |
| 731 | L->top -= 2; /* pop value and key */ | 734 | L->top -= 2; /* pop value and key */ |
| 732 | lua_unlock(L); | 735 | lua_unlock(L); |
| @@ -749,7 +752,8 @@ LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { | |||
| 749 | lua_lock(L); | 752 | lua_lock(L); |
| 750 | api_checknelems(L, 1); | 753 | api_checknelems(L, 1); |
| 751 | t = index2addr(L, idx); | 754 | t = index2addr(L, idx); |
| 752 | setsvalue2s(L, L->top++, luaS_new(L, k)); | 755 | setsvalue2s(L, L->top, luaS_new(L, k)); |
| 756 | api_incr_top(L); | ||
| 753 | luaV_settable(L, t, L->top - 1, L->top - 2); | 757 | luaV_settable(L, t, L->top - 1, L->top - 2); |
| 754 | L->top -= 2; /* pop value and key */ | 758 | L->top -= 2; /* pop value and key */ |
| 755 | lua_unlock(L); | 759 | lua_unlock(L); |
| @@ -761,7 +765,8 @@ LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) { | |||
| 761 | lua_lock(L); | 765 | lua_lock(L); |
| 762 | api_checknelems(L, 1); | 766 | api_checknelems(L, 1); |
| 763 | t = index2addr(L, idx); | 767 | t = index2addr(L, idx); |
| 764 | setivalue(L->top++, n); | 768 | setivalue(L->top, n); |
| 769 | api_incr_top(L); | ||
| 765 | luaV_settable(L, t, L->top - 1, L->top - 2); | 770 | luaV_settable(L, t, L->top - 1, L->top - 2); |
| 766 | L->top -= 2; /* pop value and key */ | 771 | L->top -= 2; /* pop value and key */ |
| 767 | lua_unlock(L); | 772 | lua_unlock(L); |
