commit 5d9b8b7cdc64777dd1ae071b52c1816fb1faa5e7
parent 1c2501fad4de5a06407500587751d71f7331a872
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Wed, 14 Feb 2001 15:03:49 -0200
more secure definition for lua_concat
Diffstat:
2 files changed, 15 insertions(+), 16 deletions(-)
diff --git a/lapi.c b/lapi.c
@@ -1,5 +1,5 @@
/*
-** $Id: lapi.c,v 1.128 2001/02/12 15:42:44 roberto Exp roberto $
+** $Id: lapi.c,v 1.129 2001/02/13 16:17:53 roberto Exp roberto $
** Lua API
** See Copyright Notice in lua.h
*/
@@ -707,14 +707,18 @@ LUA_API int lua_getn (lua_State *L, int index) {
LUA_API void lua_concat (lua_State *L, int n) {
- StkId top;
LUA_LOCK(L);
- api_check(L, n >= 2);
api_checknelems(L, n);
- top = L->top;
- luaV_strconc(L, n, top);
- L->top = top-(n-1);
- luaC_checkGC(L);
+ if (n >= 2) {
+ luaV_strconc(L, n, L->top);
+ L->top -= (n-1);
+ luaC_checkGC(L);
+ }
+ else if (n == 0) { /* push null string */
+ setsvalue(L->top, luaS_newlstr(L, NULL, 0));
+ api_incr_top(L);
+ }
+ /* else n == 1; nothing to do */
LUA_UNLOCK(L);
}
diff --git a/lauxlib.c b/lauxlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lauxlib.c,v 1.45 2001/01/25 16:45:36 roberto Exp roberto $
+** $Id: lauxlib.c,v 1.46 2001/02/02 19:02:40 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -166,10 +166,8 @@ static void adjuststack (luaL_Buffer *B) {
}
else break;
} while (toget < B->level);
- if (toget >= 2) {
- lua_concat(L, toget);
- B->level = B->level - toget + 1;
- }
+ lua_concat(L, toget);
+ B->level = B->level - toget + 1;
}
}
@@ -194,10 +192,7 @@ LUALIB_API void luaL_addstring (luaL_Buffer *B, const char *s) {
LUALIB_API void luaL_pushresult (luaL_Buffer *B) {
emptybuffer(B);
- if (B->level == 0)
- lua_pushlstring(B->L, NULL, 0);
- else if (B->level > 1)
- lua_concat(B->L, B->level);
+ lua_concat(B->L, B->level);
B->level = 1;
}