diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2008-02-14 14:03:27 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2008-02-14 14:03:27 -0200 |
commit | 843d53aabb1aa64ac55f95c1533ff29095ab585f (patch) | |
tree | e75a0a609de0c9a23c48edd3d8145b6c19402a99 /ltablib.c | |
parent | 5ac3386888347cb4d9b3ffc6d5abd1a4cfc8d1c9 (diff) | |
download | lua-843d53aabb1aa64ac55f95c1533ff29095ab585f.tar.gz lua-843d53aabb1aa64ac55f95c1533ff29095ab585f.tar.bz2 lua-843d53aabb1aa64ac55f95c1533ff29095ab585f.zip |
'table.concat' may get confused with too large limits
Diffstat (limited to 'ltablib.c')
-rw-r--r-- | ltablib.c | 24 |
1 files changed, 15 insertions, 9 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltablib.c,v 1.41 2007/09/12 20:53:24 roberto Exp roberto $ | 2 | ** $Id: ltablib.c,v 1.42 2007/11/26 16:57:33 roberto Exp roberto $ |
3 | ** Library for Table Manipulation | 3 | ** Library for Table Manipulation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -123,6 +123,15 @@ static int tremove (lua_State *L) { | |||
123 | } | 123 | } |
124 | 124 | ||
125 | 125 | ||
126 | static void addfield (lua_State *L, luaL_Buffer *b, int i) { | ||
127 | lua_rawgeti(L, 1, i); | ||
128 | if (!lua_isstring(L, -1)) | ||
129 | luaL_error(L, "invalid value (%s) at index %d in table for " | ||
130 | LUA_QL("concat"), luaL_typename(L, -1), i); | ||
131 | luaL_addvalue(b); | ||
132 | } | ||
133 | |||
134 | |||
126 | static int tconcat (lua_State *L) { | 135 | static int tconcat (lua_State *L) { |
127 | luaL_Buffer b; | 136 | luaL_Buffer b; |
128 | size_t lsep; | 137 | size_t lsep; |
@@ -132,15 +141,12 @@ static int tconcat (lua_State *L) { | |||
132 | i = luaL_optint(L, 3, 1); | 141 | i = luaL_optint(L, 3, 1); |
133 | last = luaL_opt(L, luaL_checkint, 4, (int)lua_objlen(L, 1)); | 142 | last = luaL_opt(L, luaL_checkint, 4, (int)lua_objlen(L, 1)); |
134 | luaL_buffinit(L, &b); | 143 | luaL_buffinit(L, &b); |
135 | for (; i <= last; i++) { | 144 | for (; i < last; i++) { |
136 | lua_rawgeti(L, 1, i); | 145 | addfield(L, &b, i); |
137 | if (!lua_isstring(L, -1)) | 146 | luaL_addlstring(&b, sep, lsep); |
138 | return luaL_error(L, "invalid value (%s) at index %d in table for " | ||
139 | LUA_QL("concat"), luaL_typename(L, -1), i); | ||
140 | luaL_addvalue(&b); | ||
141 | if (i != last) | ||
142 | luaL_addlstring(&b, sep, lsep); | ||
143 | } | 147 | } |
148 | if (i == last) /* add last value (if interval was not empty) */ | ||
149 | addfield(L, &b, i); | ||
144 | luaL_pushresult(&b); | 150 | luaL_pushresult(&b); |
145 | return 1; | 151 | return 1; |
146 | } | 152 | } |