diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-06-17 14:04:03 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1999-06-17 14:04:03 -0300 |
commit | 36b6fe8d175bb2aec8fc55ffb090eab90cb12fd8 (patch) | |
tree | efa22fb54a0d354249d9f3c9e0a26118d6527bd0 | |
parent | d4dce57f5ca64c65c7c49eac683b8f807e8dc02d (diff) | |
download | lua-36b6fe8d175bb2aec8fc55ffb090eab90cb12fd8.tar.gz lua-36b6fe8d175bb2aec8fc55ffb090eab90cb12fd8.tar.bz2 lua-36b6fe8d175bb2aec8fc55ffb090eab90cb12fd8.zip |
better treatment for arbitrary limits
-rw-r--r-- | lapi.c | 4 | ||||
-rw-r--r-- | lbuiltin.c | 7 | ||||
-rw-r--r-- | ldo.c | 4 | ||||
-rw-r--r-- | llex.c | 6 | ||||
-rw-r--r-- | llex.h | 6 | ||||
-rw-r--r-- | lopcodes.h | 4 | ||||
-rw-r--r-- | lparser.c | 50 | ||||
-rw-r--r-- | lstrlib.c | 9 |
8 files changed, 56 insertions, 34 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.44 1999/05/11 20:08:20 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.45 1999/05/14 12:24:20 roberto Exp roberto $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -632,7 +632,7 @@ char *lua_getobjname (lua_Object o, char **name) | |||
632 | 632 | ||
633 | 633 | ||
634 | #ifndef MAX_C_BLOCKS | 634 | #ifndef MAX_C_BLOCKS |
635 | #define MAX_C_BLOCKS 1000 | 635 | #define MAX_C_BLOCKS 1000 /* arbitrary limit */ |
636 | #endif | 636 | #endif |
637 | 637 | ||
638 | 638 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbuiltin.c,v 1.57 1999/05/24 17:53:49 roberto Exp roberto $ | 2 | ** $Id: lbuiltin.c,v 1.58 1999/05/27 20:21:03 roberto Exp roberto $ |
3 | ** Built-in functions | 3 | ** Built-in functions |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -111,7 +111,10 @@ static void error_message (void) { | |||
111 | ** model but changing "fputs" to put the strings at a proper place | 111 | ** model but changing "fputs" to put the strings at a proper place |
112 | ** (a console window or a log file, for instance). | 112 | ** (a console window or a log file, for instance). |
113 | */ | 113 | */ |
114 | #define MAXPRINT 40 | 114 | #ifndef MAXPRINT |
115 | #define MAXPRINT 40 /* arbitrary limit */ | ||
116 | #endif | ||
117 | |||
115 | static void luaB_print (void) { | 118 | static void luaB_print (void) { |
116 | lua_Object args[MAXPRINT]; | 119 | lua_Object args[MAXPRINT]; |
117 | lua_Object obj; | 120 | lua_Object obj; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 1.42 1999/05/10 13:54:01 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 1.43 1999/05/24 17:53:03 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -29,7 +29,7 @@ | |||
29 | 29 | ||
30 | 30 | ||
31 | #ifndef STACK_LIMIT | 31 | #ifndef STACK_LIMIT |
32 | #define STACK_LIMIT 6000 | 32 | #define STACK_LIMIT 6000 /* arbitrary limit */ |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | 35 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llex.c,v 1.34 1999/03/25 21:05:05 roberto Exp roberto $ | 2 | ** $Id: llex.c,v 1.35 1999/05/14 12:24:04 roberto Exp roberto $ |
3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -106,7 +106,9 @@ void luaX_setinput (LexState *LS, ZIO *z) | |||
106 | ** ======================================================= | 106 | ** ======================================================= |
107 | */ | 107 | */ |
108 | 108 | ||
109 | #define PRAGMASIZE 80 | 109 | #ifndef PRAGMASIZE |
110 | #define PRAGMASIZE 80 /* arbitrary limit */ | ||
111 | #endif | ||
110 | 112 | ||
111 | static void skipspace (LexState *LS) { | 113 | static void skipspace (LexState *LS) { |
112 | while (LS->current == ' ' || LS->current == '\t' || LS->current == '\r') | 114 | while (LS->current == ' ' || LS->current == '\t' || LS->current == '\r') |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: llex.h,v 1.10 1998/07/24 18:02:38 roberto Exp roberto $ | 2 | ** $Id: llex.h,v 1.11 1999/02/25 19:13:56 roberto Exp roberto $ |
3 | ** Lexical Analyzer | 3 | ** Lexical Analyzer |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -25,7 +25,9 @@ enum RESERVED { | |||
25 | NAME, CONC, DOTS, EQ, GE, LE, NE, NUMBER, STRING, EOS}; | 25 | NAME, CONC, DOTS, EQ, GE, LE, NE, NUMBER, STRING, EOS}; |
26 | 26 | ||
27 | 27 | ||
28 | #define MAX_IFS 5 | 28 | #ifndef MAX_IFS |
29 | #define MAX_IFS 5 /* arbitrary limit */ | ||
30 | #endif | ||
29 | 31 | ||
30 | /* "ifstate" keeps the state of each nested $if the lexical is dealing with. */ | 32 | /* "ifstate" keeps the state of each nested $if the lexical is dealing with. */ |
31 | 33 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lopcodes.h,v 1.31 1999/03/05 21:16:07 roberto Exp roberto $ | 2 | ** $Id: lopcodes.h,v 1.32 1999/03/10 14:09:45 roberto Exp roberto $ |
3 | ** Opcodes for Lua virtual machine | 3 | ** Opcodes for Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -113,7 +113,7 @@ CHECKSTACK /* b (assert #temporaries == b; only for internal debuging!) */ | |||
113 | #define RFIELDS_PER_FLUSH 32 /* records (SETMAP) */ | 113 | #define RFIELDS_PER_FLUSH 32 /* records (SETMAP) */ |
114 | #define LFIELDS_PER_FLUSH 64 /* FPF - lists (SETLIST) */ | 114 | #define LFIELDS_PER_FLUSH 64 /* FPF - lists (SETLIST) */ |
115 | 115 | ||
116 | #define ZEROVARARG 64 | 116 | #define ZEROVARARG 128 |
117 | 117 | ||
118 | 118 | ||
119 | /* maximum value of an arg of 3 bytes; must fit in an "int" */ | 119 | /* maximum value of an arg of 3 bytes; must fit in an "int" */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 1.35 1999/06/16 13:22:04 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 1.36 1999/06/16 13:35:01 roberto Exp roberto $ |
3 | ** LL(1) Parser and code generator for Lua | 3 | ** LL(1) Parser and code generator for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -22,26 +22,32 @@ | |||
22 | #include "lzio.h" | 22 | #include "lzio.h" |
23 | 23 | ||
24 | 24 | ||
25 | /* for limit numbers in error messages */ | ||
26 | #define MES_LIM(x) "(limit=" x ")" | ||
27 | |||
28 | 25 | ||
29 | /* size of a "normal" jump instruction: OpCode + 1 byte */ | 26 | /* size of a "normal" jump instruction: OpCode + 1 byte */ |
30 | #define JMPSIZE 2 | 27 | #define JMPSIZE 2 |
31 | 28 | ||
32 | /* maximum number of local variables */ | 29 | /* maximum number of local variables */ |
33 | #define MAXLOCALS 200 | 30 | #ifndef MAXLOCALS |
34 | #define SMAXLOCALS "200" | 31 | #define MAXLOCALS 200 /* arbitrary limit (<256) */ |
32 | #endif | ||
35 | 33 | ||
36 | 34 | ||
37 | /* maximum number of upvalues */ | 35 | /* maximum number of upvalues */ |
38 | #define MAXUPVALUES 32 | 36 | #ifndef MAXUPVALUES |
39 | #define SMAXUPVALUES "32" | 37 | #define MAXUPVALUES 32 /* arbitrary limit (<256) */ |
38 | #endif | ||
40 | 39 | ||
41 | 40 | ||
42 | /* maximum number of variables in the left side of an assignment */ | 41 | /* maximum number of variables in the left side of an assignment */ |
43 | #define MAXVARSLH 100 | 42 | #ifndef MAXVARSLH |
44 | #define SMAXVARSLH "100" | 43 | #define MAXVARSLH 100 /* arbitrary limit (<255) */ |
44 | #endif | ||
45 | |||
46 | |||
47 | /* maximum number of parameters in a function */ | ||
48 | #ifndef MAXPARAMS | ||
49 | #define MAXPARAMS 100 /* arbitrary limit (<ZEROVARARG) */ | ||
50 | #endif | ||
45 | 51 | ||
46 | 52 | ||
47 | /* | 53 | /* |
@@ -136,6 +142,15 @@ static void var_or_func_tail (LexState *ls, vardesc *v); | |||
136 | 142 | ||
137 | 143 | ||
138 | 144 | ||
145 | static void checklimit (LexState *ls, int val, int limit, char *msg) { | ||
146 | if (val > limit) { | ||
147 | char buff[100]; | ||
148 | sprintf(buff, "too many %s (limit=%d)", msg, limit); | ||
149 | luaX_error(ls, buff); | ||
150 | } | ||
151 | } | ||
152 | |||
153 | |||
139 | static void check_pc (FuncState *fs, int n) { | 154 | static void check_pc (FuncState *fs, int n) { |
140 | luaM_growvector(fs->f->code, fs->pc, n, Byte, codeEM, MAX_INT); | 155 | luaM_growvector(fs->f->code, fs->pc, n, Byte, codeEM, MAX_INT); |
141 | } | 156 | } |
@@ -310,8 +325,7 @@ static void luaI_unregisterlocalvar (FuncState *fs, int line) { | |||
310 | 325 | ||
311 | static void store_localvar (LexState *ls, TaggedString *name, int n) { | 326 | static void store_localvar (LexState *ls, TaggedString *name, int n) { |
312 | FuncState *fs = ls->fs; | 327 | FuncState *fs = ls->fs; |
313 | if (fs->nlocalvar+n >= MAXLOCALS) | 328 | checklimit(ls, fs->nlocalvar+n+1, MAXLOCALS, "local variables"); |
314 | luaX_error(ls, "too many local variables " MES_LIM(SMAXLOCALS)); | ||
315 | fs->localvar[fs->nlocalvar+n] = name; | 329 | fs->localvar[fs->nlocalvar+n] = name; |
316 | luaI_registerlocalvar(fs, name, ls->linenumber); | 330 | luaI_registerlocalvar(fs, name, ls->linenumber); |
317 | } | 331 | } |
@@ -369,9 +383,8 @@ static int indexupvalue (LexState *ls, TaggedString *n) { | |||
369 | return i; | 383 | return i; |
370 | } | 384 | } |
371 | /* new one */ | 385 | /* new one */ |
372 | if (++(fs->nupvalues) > MAXUPVALUES) | 386 | ++(fs->nupvalues); |
373 | luaX_error(ls, "too many upvalues in a single function " | 387 | checklimit(ls, fs->nupvalues, MAXUPVALUES, "upvalues"); |
374 | MES_LIM(SMAXUPVALUES)); | ||
375 | fs->upvalues[i] = v; /* i = fs->nupvalues - 1 */ | 388 | fs->upvalues[i] = v; /* i = fs->nupvalues - 1 */ |
376 | return i; | 389 | return i; |
377 | } | 390 | } |
@@ -439,6 +452,7 @@ static void adjust_mult_assign (LexState *ls, int nvars, listdesc *d) { | |||
439 | static void code_args (LexState *ls, int nparams, int dots) { | 452 | static void code_args (LexState *ls, int nparams, int dots) { |
440 | FuncState *fs = ls->fs; | 453 | FuncState *fs = ls->fs; |
441 | fs->nlocalvar += nparams; /* "self" may already be there */ | 454 | fs->nlocalvar += nparams; /* "self" may already be there */ |
455 | checklimit(ls, fs->nlocalvar, MAXPARAMS, "parameters"); | ||
442 | nparams = fs->nlocalvar; | 456 | nparams = fs->nlocalvar; |
443 | if (!dots) { | 457 | if (!dots) { |
444 | fs->f->code[1] = (Byte)nparams; /* fill-in arg information */ | 458 | fs->f->code[1] = (Byte)nparams; /* fill-in arg information */ |
@@ -917,7 +931,7 @@ static int priority [POW+1] = {5, 5, 1, 1, 1, 1, 1, 1, 2, 3, 3, 4, 4, 6}; | |||
917 | static OpCode opcodes [POW+1] = {NOTOP, MINUSOP, EQOP, NEQOP, GTOP, LTOP, | 931 | static OpCode opcodes [POW+1] = {NOTOP, MINUSOP, EQOP, NEQOP, GTOP, LTOP, |
918 | LEOP, GEOP, CONCOP, ADDOP, SUBOP, MULTOP, DIVOP, POWOP}; | 932 | LEOP, GEOP, CONCOP, ADDOP, SUBOP, MULTOP, DIVOP, POWOP}; |
919 | 933 | ||
920 | #define MAXOPS 20 /* op's stack size */ | 934 | #define MAXOPS 20 /* op's stack size (arbitrary limit) */ |
921 | 935 | ||
922 | typedef struct stack_op { | 936 | typedef struct stack_op { |
923 | int ops[MAXOPS]; | 937 | int ops[MAXOPS]; |
@@ -1226,9 +1240,7 @@ static void decinit (LexState *ls, listdesc *d) { | |||
1226 | 1240 | ||
1227 | static int assignment (LexState *ls, vardesc *v, int nvars) { | 1241 | static int assignment (LexState *ls, vardesc *v, int nvars) { |
1228 | int left = 0; | 1242 | int left = 0; |
1229 | if (nvars > MAXVARSLH) | 1243 | checklimit(ls, nvars, MAXVARSLH, "variables in a multiple assignment"); |
1230 | luaX_error(ls, "too many variables in a multiple assignment " | ||
1231 | MES_LIM(SMAXVARSLH)); | ||
1232 | unloaddot(ls, v); | 1244 | unloaddot(ls, v); |
1233 | if (ls->token == ',') { /* assignment -> ',' NAME assignment */ | 1245 | if (ls->token == ',') { /* assignment -> ',' NAME assignment */ |
1234 | vardesc nv; | 1246 | vardesc nv; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstrlib.c,v 1.30 1999/05/05 19:22:26 roberto Exp roberto $ | 2 | ** $Id: lstrlib.c,v 1.31 1999/05/14 12:24:04 roberto Exp roberto $ |
3 | ** Standard library for strings and pattern-matching | 3 | ** Standard library for strings and pattern-matching |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -117,7 +117,10 @@ static void str_char (void) { | |||
117 | ** ======================================================= | 117 | ** ======================================================= |
118 | */ | 118 | */ |
119 | 119 | ||
120 | #define MAX_CAPT 32 | 120 | #ifndef MAX_CAPT |
121 | #define MAX_CAPT 32 /* arbitrary limit */ | ||
122 | #endif | ||
123 | |||
121 | 124 | ||
122 | struct Capture { | 125 | struct Capture { |
123 | char *src_end; /* end ('\0') of source string */ | 126 | char *src_end; /* end ('\0') of source string */ |
@@ -499,7 +502,7 @@ static void luaI_addquoted (int arg) { | |||
499 | } | 502 | } |
500 | 503 | ||
501 | /* maximum size of each format specification (such as '%-099.99d') */ | 504 | /* maximum size of each format specification (such as '%-099.99d') */ |
502 | #define MAX_FORMAT 20 | 505 | #define MAX_FORMAT 20 /* arbitrary limit */ |
503 | 506 | ||
504 | static void str_format (void) { | 507 | static void str_format (void) { |
505 | int arg = 1; | 508 | int arg = 1; |