From: Fabrice Bellard Date: Tue, 24 Nov 2026 17:19:23 +0000 (+0100) Subject: Limit the number of closure variables of a direct eval (bnoordhuis) X-Git-Url: https://git.kaiwu.me/http/%22../$%7BGITURL%7D/doc/static/gitweb.js?a=commitdiff_plain;h=9032e44db5863f91c8ba3b96403306d82e9e9d7a;p=quickjs.git Limit the number of closure variables of a direct eval (bnoordhuis) --- diff --git a/quickjs.c b/quickjs.c index b9bf0e7..9e60c88 100644 --- 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; }