diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-02-14 15:04:11 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2001-02-14 15:04:11 -0200 |
commit | 5d9b8b7cdc64777dd1ae071b52c1816fb1faa5e7 (patch) | |
tree | 5b35aecdfb285953765e9b2783f7518f22101eda | |
parent | 1c2501fad4de5a06407500587751d71f7331a872 (diff) | |
download | lua-5d9b8b7cdc64777dd1ae071b52c1816fb1faa5e7.tar.gz lua-5d9b8b7cdc64777dd1ae071b52c1816fb1faa5e7.tar.bz2 lua-5d9b8b7cdc64777dd1ae071b52c1816fb1faa5e7.zip |
more secure definition for lua_concat
-rw-r--r-- | lapi.c | 18 | ||||
-rw-r--r-- | lauxlib.c | 13 |
2 files changed, 15 insertions, 16 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.128 2001/02/12 15:42:44 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.129 2001/02/13 16:17:53 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 | */ |
@@ -707,14 +707,18 @@ LUA_API int lua_getn (lua_State *L, int index) { | |||
707 | 707 | ||
708 | 708 | ||
709 | LUA_API void lua_concat (lua_State *L, int n) { | 709 | LUA_API void lua_concat (lua_State *L, int n) { |
710 | StkId top; | ||
711 | LUA_LOCK(L); | 710 | LUA_LOCK(L); |
712 | api_check(L, n >= 2); | ||
713 | api_checknelems(L, n); | 711 | api_checknelems(L, n); |
714 | top = L->top; | 712 | if (n >= 2) { |
715 | luaV_strconc(L, n, top); | 713 | luaV_strconc(L, n, L->top); |
716 | L->top = top-(n-1); | 714 | L->top -= (n-1); |
717 | luaC_checkGC(L); | 715 | luaC_checkGC(L); |
716 | } | ||
717 | else if (n == 0) { /* push null string */ | ||
718 | setsvalue(L->top, luaS_newlstr(L, NULL, 0)); | ||
719 | api_incr_top(L); | ||
720 | } | ||
721 | /* else n == 1; nothing to do */ | ||
718 | LUA_UNLOCK(L); | 722 | LUA_UNLOCK(L); |
719 | } | 723 | } |
720 | 724 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.45 2001/01/25 16:45:36 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.46 2001/02/02 19:02:40 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -166,10 +166,8 @@ static void adjuststack (luaL_Buffer *B) { | |||
166 | } | 166 | } |
167 | else break; | 167 | else break; |
168 | } while (toget < B->level); | 168 | } while (toget < B->level); |
169 | if (toget >= 2) { | 169 | lua_concat(L, toget); |
170 | lua_concat(L, toget); | 170 | B->level = B->level - toget + 1; |
171 | B->level = B->level - toget + 1; | ||
172 | } | ||
173 | } | 171 | } |
174 | } | 172 | } |
175 | 173 | ||
@@ -194,10 +192,7 @@ LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) { | |||
194 | 192 | ||
195 | LUALIB_API void luaL_pushresult (luaL_Buffer *B) { | 193 | LUALIB_API void luaL_pushresult (luaL_Buffer *B) { |
196 | emptybuffer(B); | 194 | emptybuffer(B); |
197 | if (B->level == 0) | 195 | lua_concat(B->L, B->level); |
198 | lua_pushlstring(B->L, NULL, 0); | ||
199 | else if (B->level > 1) | ||
200 | lua_concat(B->L, B->level); | ||
201 | B->level = 1; | 196 | B->level = 1; |
202 | } | 197 | } |
203 | 198 | ||