]> git.kaiwu.me - njs.git/commitdiff
Modules: use the caller context for QuickJS string conversion
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 5 Nov 2026 00:44:13 +0000 (16:44 -0800)
committerDmitry Volyntsev <xeioexception@gmail.com>
Wed, 11 Nov 2026 21:33:45 +0000 (13:33 -0800)
String conversion recovered the context through ctx->engine even though
both the JSContext and destination pool were already supplied.  During
module evaluation the engine is not published yet, so synchronous
Request and Headers construction could dereference NULL.

Use the supplied context without changing allocation or copy behavior.
The dependency was introduced in 201b1276.

nginx/ngx_js.c

index 1ba8f712e731d9ace6a25d52549ebea863db92e5..77fd0b26425510343d721b8db71f06470e73e454 100644 (file)
@@ -1694,11 +1694,6 @@ ngx_qjs_string(JSContext *cx, ngx_pool_t *pool, JSValueConst val,
     u_char        *start;
     JSValue        buffer;
     const char    *str;
-    ngx_js_ctx_t  *ctx;
-    ngx_engine_t  *e;
-
-    ctx = ngx_qjs_external_ctx(cx, JS_GetContextOpaque(cx));
-    e = ctx->engine;
 
     if (JS_IsNullOrUndefined(val)) {
         dst->data = NULL;
@@ -1706,8 +1701,6 @@ ngx_qjs_string(JSContext *cx, ngx_pool_t *pool, JSValueConst val,
         return NGX_OK;
     }
 
-    cx = e->u.qjs.ctx;
-
     if (JS_IsString(val)) {
         goto string;
     }