aboutsummaryrefslogtreecommitdiff
path: root/lstring.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-11-19 13:52:40 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-11-19 13:52:40 -0200
commit6f1ea817f5827523f8c7e429ab023e5984a84343 (patch)
tree778c20b8816afb4ee5cfc3b988ec1c31efbb7b75 /lstring.c
parentcdcb236747a728e3ef0855aa16a42b73e7a9a6c6 (diff)
downloadlua-6f1ea817f5827523f8c7e429ab023e5984a84343.tar.gz
lua-6f1ea817f5827523f8c7e429ab023e5984a84343.tar.bz2
lua-6f1ea817f5827523f8c7e429ab023e5984a84343.zip
better control over memory-size overflows
Diffstat (limited to 'lstring.c')
-rw-r--r--lstring.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/lstring.c b/lstring.c
index 13b75086..99c3f0b6 100644
--- a/lstring.c
+++ b/lstring.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstring.c,v 2.2 2004/04/30 20:13:38 roberto Exp roberto $ 2** $Id: lstring.c,v 2.3 2004/08/24 20:12:06 roberto Exp roberto $
3** String table (keeps all strings handled by Lua) 3** String table (keeps all strings handled by Lua)
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -49,8 +49,11 @@ void luaS_resize (lua_State *L, int newsize) {
49 49
50static TString *newlstr (lua_State *L, const char *str, size_t l, 50static TString *newlstr (lua_State *L, const char *str, size_t l,
51 unsigned int h) { 51 unsigned int h) {
52 TString *ts = cast(TString *, luaM_malloc(L, sizestring(l))); 52 TString *ts;
53 stringtable *tb; 53 stringtable *tb;
54 if (l+1 > (MAX_SIZET - sizeof(TString))/sizeof(char))
55 luaM_toobig(L);
56 ts = cast(TString *, luaM_malloc(L, (l+1)*sizeof(char)+sizeof(TString)));
54 ts->tsv.len = l; 57 ts->tsv.len = l;
55 ts->tsv.hash = h; 58 ts->tsv.hash = h;
56 ts->tsv.marked = luaC_white(G(L)); 59 ts->tsv.marked = luaC_white(G(L));
@@ -92,7 +95,9 @@ TString *luaS_newlstr (lua_State *L, const char *str, size_t l) {
92 95
93Udata *luaS_newudata (lua_State *L, size_t s) { 96Udata *luaS_newudata (lua_State *L, size_t s) {
94 Udata *u; 97 Udata *u;
95 u = cast(Udata *, luaM_malloc(L, sizeudata(s))); 98 if (s > MAX_SIZET - sizeof(Udata))
99 luaM_toobig(L);
100 u = cast(Udata *, luaM_malloc(L, s + sizeof(Udata)));
96 u->uv.marked = luaC_white(G(L)); /* is not finalized */ 101 u->uv.marked = luaC_white(G(L)); /* is not finalized */
97 u->uv.tt = LUA_TUSERDATA; 102 u->uv.tt = LUA_TUSERDATA;
98 u->uv.len = s; 103 u->uv.len = s;