]> git.kaiwu.me - quickjs.git/commitdiff
Limit the number of closure variables of a direct eval (bnoordhuis)
authorFabrice Bellard <fabrice@bellard.org>
Tue, 24 Nov 2026 17:19:23 +0000 (18:19 +0100)
committerFabrice Bellard <fabrice@bellard.org>
Tue, 24 Nov 2026 17:19:23 +0000 (18:19 +0100)
quickjs.c

index b9bf0e7ffc41caa06d1e47252b923196a4c30af1..9e60c883c7016094a73cc8b22fd8dc96d7d259a2 100644 (file)
--- a/quickjs.c
+++ b/quickjs.c
@@ -35183,6 +35183,15 @@ static __exception int add_closure_variables(JSContext *ctx, JSFunctionDef *s,
         cv->var_idx = i;
         cv->var_name = JS_DupAtom(ctx, cv0->var_name);
     }
+    // same limit as add_closure_var(): the indexes and the count are
+    // stored on 16 bits. The arguments, variables and closure variables
+    // of the calling function are limited separately, so their sum can
+    // exceed it.
+    if (s->closure_var_count > JS_MAX_LOCAL_VARS) {
+        JS_ThrowSyntaxError(ctx, "too many closure variables used (only %d allowed)",
+                            JS_MAX_LOCAL_VARS - 1);
+        return -1;
+    }
     return 0;
 }