diff options
| -rw-r--r-- | lobject.c | 10 |
1 files changed, 8 insertions, 2 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lobject.c,v 2.109 2015/12/14 11:53:27 roberto Exp roberto $ | 2 | ** $Id: lobject.c,v 2.110 2016/05/02 14:00:32 roberto Exp roberto $ |
| 3 | ** Some generic functions over Lua objects | 3 | ** Some generic functions over Lua objects |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -293,6 +293,9 @@ static const char *l_str2d (const char *s, lua_Number *result) { | |||
| 293 | } | 293 | } |
| 294 | 294 | ||
| 295 | 295 | ||
| 296 | #define MAXBY10 cast(lua_Unsigned, LUA_MAXINTEGER / 10) | ||
| 297 | #define MAXLASTD cast_int(LUA_MAXINTEGER % 10) | ||
| 298 | |||
| 296 | static const char *l_str2int (const char *s, lua_Integer *result) { | 299 | static const char *l_str2int (const char *s, lua_Integer *result) { |
| 297 | lua_Unsigned a = 0; | 300 | lua_Unsigned a = 0; |
| 298 | int empty = 1; | 301 | int empty = 1; |
| @@ -309,7 +312,10 @@ static const char *l_str2int (const char *s, lua_Integer *result) { | |||
| 309 | } | 312 | } |
| 310 | else { /* decimal */ | 313 | else { /* decimal */ |
| 311 | for (; lisdigit(cast_uchar(*s)); s++) { | 314 | for (; lisdigit(cast_uchar(*s)); s++) { |
| 312 | a = a * 10 + *s - '0'; | 315 | int d = *s - '0'; |
| 316 | if (a >= MAXBY10 && (a > MAXBY10 || d > MAXLASTD + neg)) /* overflow? */ | ||
| 317 | return NULL; /* do not accept it (as integer) */ | ||
| 318 | a = a * 10 + d; | ||
| 313 | empty = 0; | 319 | empty = 0; |
| 314 | } | 320 | } |
| 315 | } | 321 | } |
