diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-10-28 14:45:51 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-10-28 14:45:51 -0300 |
| commit | cfb79b17513d42d58846b34e071409795c51f604 (patch) | |
| tree | 85b576228baf487f8d3426d42dad7229218c67e5 | |
| parent | 3e1a1f28362d53104a6ef09fadd902e91657f8ce (diff) | |
| download | lua-cfb79b17513d42d58846b34e071409795c51f604.tar.gz lua-cfb79b17513d42d58846b34e071409795c51f604.tar.bz2 lua-cfb79b17513d42d58846b34e071409795c51f604.zip | |
more secure way to compute final string length
| -rw-r--r-- | lvm.c | 9 |
1 files changed, 4 insertions, 5 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lvm.c,v 2.14 2004/09/15 20:39:42 roberto Exp $ | 2 | ** $Id: lvm.c,v 2.15 2004/10/04 19:01:53 roberto Exp roberto $ |
| 3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -303,15 +303,14 @@ void luaV_concat (lua_State *L, int total, int last) { | |||
| 303 | luaG_concaterror(L, top-2, top-1); | 303 | luaG_concaterror(L, top-2, top-1); |
| 304 | } else if (tsvalue(top-1)->len > 0) { /* if len=0, do nothing */ | 304 | } else if (tsvalue(top-1)->len > 0) { /* if len=0, do nothing */ |
| 305 | /* at least two string values; get as many as possible */ | 305 | /* at least two string values; get as many as possible */ |
| 306 | lu_mem tl = cast(lu_mem, tsvalue(top-1)->len) + | 306 | size_t tl = tsvalue(top-1)->len; |
| 307 | cast(lu_mem, tsvalue(top-2)->len); | ||
| 308 | char *buffer; | 307 | char *buffer; |
| 309 | int i; | 308 | int i; |
| 310 | while (n < total && tostring(L, top-n-1)) { /* collect total length */ | 309 | /* collect total length */ |
| 310 | for (n = 1; n < total && tostring(L, top-n-1); n++) { | ||
| 311 | size_t l = tsvalue(top-n-1)->len; | 311 | size_t l = tsvalue(top-n-1)->len; |
| 312 | if (l >= MAX_SIZET - tl) luaG_runerror(L, "string length overflow"); | 312 | if (l >= MAX_SIZET - tl) luaG_runerror(L, "string length overflow"); |
| 313 | tl += l; | 313 | tl += l; |
| 314 | n++; | ||
| 315 | } | 314 | } |
| 316 | buffer = luaZ_openspace(L, &G(L)->buff, tl); | 315 | buffer = luaZ_openspace(L, &G(L)->buff, tl); |
| 317 | tl = 0; | 316 | tl = 0; |
