summaryrefslogtreecommitdiff
path: root/src/lobject.c
diff options
context:
space:
mode:
authorLua Team <team@lua.org>2016-06-06 12:00:00 +0000
committerrepogen <>2016-06-06 12:00:00 +0000
commit7d19fe6f4d59543ce5a61b640350805064ac5652 (patch)
tree3747598941015c96562235b39419ae3fcc9a22c5 /src/lobject.c
parentf65e2704f4ab323e2a4912de043a1943a95c0fd7 (diff)
downloadlua-github-5.3.3-rc3.tar.gz
Diffstat (limited to 'src/lobject.c')
-rw-r--r--src/lobject.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/lobject.c b/src/lobject.c
index 04f45da2..a44b3850 100644
--- a/src/lobject.c
+++ b/src/lobject.c
@@ -1,5 +1,5 @@
/*
-** $Id: lobject.c,v 2.110 2016/05/02 14:00:32 roberto Exp $
+** $Id: lobject.c,v 2.111 2016/05/20 14:07:48 roberto Exp $
** Some generic functions over Lua objects
** See Copyright Notice in lua.h
*/
@@ -293,6 +293,9 @@ static const char *l_str2d (const char *s, lua_Number *result) {
}
+#define MAXBY10 cast(lua_Unsigned, LUA_MAXINTEGER / 10)
+#define MAXLASTD cast_int(LUA_MAXINTEGER % 10)
+
static const char *l_str2int (const char *s, lua_Integer *result) {
lua_Unsigned a = 0;
int empty = 1;
@@ -309,7 +312,10 @@ static const char *l_str2int (const char *s, lua_Integer *result) {
}
else { /* decimal */
for (; lisdigit(cast_uchar(*s)); s++) {
- a = a * 10 + *s - '0';
+ int d = *s - '0';
+ if (a >= MAXBY10 && (a > MAXBY10 || d > MAXLASTD + neg)) /* overflow? */
+ return NULL; /* do not accept it (as integer) */
+ a = a * 10 + d;
empty = 0;
}
}