summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-06-20 12:06:51 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2013-06-20 12:06:51 -0300
commit7c4cc505dbf67f9a0c09583588c9697d9f239a07 (patch)
treecd928a9bb143790ee9a327c139ddcccf96426091
parent453450d68751f74f0fab44bd96725a5606d2d9a1 (diff)
downloadlua-7c4cc505dbf67f9a0c09583588c9697d9f239a07.tar.gz
lua-7c4cc505dbf67f9a0c09583588c9697d9f239a07.tar.bz2
lua-7c4cc505dbf67f9a0c09583588c9697d9f239a07.zip
added "reasonable" limit for 'string.rep' (otherwise it is too easy
to crash the machine)
-rw-r--r--lstrlib.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/lstrlib.c b/lstrlib.c
index cb27492c..8ca34691 100644
--- a/lstrlib.c
+++ b/lstrlib.c
@@ -1,11 +1,12 @@
1/* 1/*
2** $Id: lstrlib.c,v 1.180 2013/06/07 14:51:10 roberto Exp roberto $ 2** $Id: lstrlib.c,v 1.181 2013/06/19 14:29:01 roberto Exp roberto $
3** Standard library for string operations and pattern-matching 3** Standard library for string operations and pattern-matching
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
6 6
7 7
8#include <ctype.h> 8#include <ctype.h>
9#include <limits.h>
9#include <stddef.h> 10#include <stddef.h>
10#include <stdio.h> 11#include <stdio.h>
11#include <stdlib.h> 12#include <stdlib.h>
@@ -102,8 +103,12 @@ static int str_upper (lua_State *L) {
102} 103}
103 104
104 105
105/* reasonable limit to avoid arithmetic overflow */ 106/* reasonable limit to avoid arithmetic overflow and strings too big */
106#define MAXSIZE ((~(size_t)0) >> 1) 107#if INT_MAX / 2 <= 0x10000000
108#define MAXSIZE ((size_t)(INT_MAX / 2))
109#else
110#define MAXSIZE ((size_t)0x10000000)
111#endif
107 112
108static int str_rep (lua_State *L) { 113static int str_rep (lua_State *L) {
109 size_t l, lsep; 114 size_t l, lsep;