lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi all,

I use Lua in some embedded device and I have found some mysterious restart records in log.
I dig into the problem and I discover this error mechanics:
-ftrapv in C_FLAGS
LUA_NUMBER int

Lua code: local n = 12345678901234567890
My function strtod used by parser returns LUA_MININTEGER without signaling an error through endptr.
Then function luaH_getint is invoked from assignment with key = LUA_MININTEGER

I propose small patch to prevent integer overflow and raise of SIGILL from ftrapv:
--- ltable.c    2015-06-09 16:21:13.000000000 +0200
+++ ltable.c    2015-11-07 12:02:22.189074799 +0100
@@ -501,7 +501,7 @@
 */
 const TValue *luaH_getint (Table *t, lua_Integer key) {
   /* (1 <= key && key <= t->sizearray) */
-  if (l_castS2U(key - 1) < t->sizearray)
+  if (key > LUA_MININTEGER && l_castS2U(key - 1) < t->sizearray)
     return &t->array[key - 1];
   else {
     Node *n = hashint(t, key);

Miroslav