diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-02-07 13:39:54 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-02-07 13:39:54 -0300 |
commit | 0c9bec0d38ed3d2c45d7be4e764a0bcffef98be1 (patch) | |
tree | 05fd1ba56705dc0a1728e1bedda7961cc96414c1 /ltablib.c | |
parent | c31d6774ac7db4cfbc548ce507ae65ab6036f873 (diff) | |
download | lua-0c9bec0d38ed3d2c45d7be4e764a0bcffef98be1.tar.gz lua-0c9bec0d38ed3d2c45d7be4e764a0bcffef98be1.tar.bz2 lua-0c9bec0d38ed3d2c45d7be4e764a0bcffef98be1.zip |
Better handling of size limit when resizing a table
Avoid silent conversions from int to unsigned int when calling
'luaH_resize'; avoid silent conversions from lua_Integer to int in
'table.create'; MAXASIZE corrected for the new implementation of arrays;
'luaH_resize' checks explicitly whether new size respects MAXASIZE.
(Even constructors were bypassing that check.)
Diffstat (limited to 'ltablib.c')
-rw-r--r-- | ltablib.c | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -59,8 +59,10 @@ static void checktab (lua_State *L, int arg, int what) { | |||
59 | 59 | ||
60 | 60 | ||
61 | static int tcreate (lua_State *L) { | 61 | static int tcreate (lua_State *L) { |
62 | int sizeseq = (int)luaL_checkinteger(L, 1); | 62 | lua_Unsigned sizeseq = (lua_Unsigned)luaL_checkinteger(L, 1); |
63 | int sizerest = (int)luaL_optinteger(L, 2, 0); | 63 | lua_Unsigned sizerest = (lua_Unsigned)luaL_optinteger(L, 2, 0); |
64 | luaL_argcheck(L, sizeseq <= UINT_MAX, 1, "out of range"); | ||
65 | luaL_argcheck(L, sizerest <= UINT_MAX, 2, "out of range"); | ||
64 | lua_createtable(L, sizeseq, sizerest); | 66 | lua_createtable(L, sizeseq, sizerest); |
65 | return 1; | 67 | return 1; |
66 | } | 68 | } |