shithub: libmujs

Download patch

ref: 8c868344b207fbcaee4622fb6c0b97d1bd5c79a9
parent: 6b522a0b1f8559a78341a3c7163772b2f41d9a54
author: gardhr <24468810+gardhr@users.noreply.github.com>
date: Sun Nov 24 09:55:19 EST 2019

Issue 114: Allow compile time limits to be configured.

--- a/jsdump.c
+++ b/jsdump.c
@@ -799,7 +799,7 @@
 
 		switch (c) {
 		case OP_INTEGER:
-			printf(" %d", (*p++) - 32768);
+			printf(" %ld", (long)((*p++) - 32768));
 			break;
 		case OP_NUMBER:
 			printf(" %.9g", F->numtab[*p++]);
@@ -840,7 +840,7 @@
 		case OP_JFALSE:
 		case OP_JCASE:
 		case OP_TRY:
-			printf(" %d", *p++);
+			printf(" %ld", (long)*p++);
 			break;
 		}
 
--- a/jsi.h
+++ b/jsi.h
@@ -69,14 +69,29 @@
 
 /* Limits */
 
+#ifndef JS_STACKSIZE
 #define JS_STACKSIZE 256	/* value stack size */
+#endif
+#ifndef JS_ENVLIMIT
 #define JS_ENVLIMIT 64		/* environment stack size */
+#endif
+#ifndef JS_TRYLIMIT
 #define JS_TRYLIMIT 64		/* exception stack size */
+#endif
+#ifndef JS_GCLIMIT
 #define JS_GCLIMIT 10000	/* run gc cycle every N allocations */
+#endif
+#ifndef JS_ASTLIMIT
 #define JS_ASTLIMIT 100		/* max nested expressions */
+#endif
 
 /* instruction size -- change to int if you get integer overflow syntax errors */
+
+#ifdef JS_INSTRUCTION
+typedef JS_INSTRUCTION js_Instruction;
+#else
 typedef unsigned short js_Instruction;
+#endif
 
 /* String interning */
 
--- a/regexp.c
+++ b/regexp.c
@@ -14,9 +14,21 @@
 #define nelem(a) (int)(sizeof (a) / sizeof (a)[0])
 
 #define REPINF 255
+#ifndef MAXSUB
 #define MAXSUB REG_MAXSUB
+#endif
+#ifndef MAXPROG
 #define MAXPROG (32 << 10)
+#endif
+#ifndef MAXREC
 #define MAXREC 1024
+#endif
+#ifndef MAXSPAN
+#define MAXSPAN 64
+#endif
+#ifndef MAXCLASS
+#define MAXCLASS 16
+#endif
 
 typedef struct Reclass Reclass;
 typedef struct Renode Renode;
@@ -25,7 +37,7 @@
 
 struct Reclass {
 	Rune *end;
-	Rune spans[64];
+	Rune spans[MAXSPAN];
 };
 
 struct Reprog {
@@ -32,7 +44,7 @@
 	Reinst *start, *end;
 	int flags;
 	int nsub;
-	Reclass cclass[16];
+	Reclass cclass[MAXCLASS];
 };
 
 struct cstate {
@@ -194,7 +206,7 @@
 {
 	if (a > b)
 		die(g, "invalid character class range");
-	if (g->yycc->end + 2 == g->yycc->spans + nelem(g->yycc->spans))
+	if (g->yycc->end + 2 >= g->yycc->spans + nelem(g->yycc->spans))
 		die(g, "too many character class ranges");
 	*g->yycc->end++ = a;
 	*g->yycc->end++ = b;