shithub: libmujs

Download patch

ref: 3451b6ca9632b2146eb30164eae764921d8025b6
parent: 88f6d86b6c782c73843a540b69a96f4c09daa507
author: Tor Andersson <tor.andersson@artifex.com>
date: Thu Jun 9 10:58:02 EDT 2022

Guard state initialization with try to avoid panic in initialization.

--- a/jsstate.c
+++ b/jsstate.c
@@ -322,6 +322,11 @@
 	J->nextref = 0;
 	J->gcthresh = 0; /* reaches stability within ~ 2-5 GC cycles */
 
+	if (js_try(J)) {
+		js_freestate(J);
+		return NULL;
+	}
+
 	J->R = jsV_newobject(J, JS_COBJECT, NULL);
 	J->G = jsV_newobject(J, JS_COBJECT, NULL);
 	J->E = jsR_newenvironment(J, J->G, NULL);
@@ -329,5 +334,6 @@
 
 	jsB_init(J);
 
+	js_endtry(J);
 	return J;
 }
--- a/main.c
+++ b/main.c
@@ -311,6 +311,10 @@
 	}
 
 	J = js_newstate(NULL, NULL, strict ? JS_STRICT : 0);
+	if (!J) {
+		fprintf(stderr, "Could not initialize MuJS.\n");
+		exit(1);
+	}
 
 	js_newcfunction(J, jsB_gc, "gc", 0);
 	js_setglobal(J, "gc");