From: Dmitry Volyntsev Date: Thu, 5 Nov 2026 00:49:38 +0000 (-0800) Subject: Modules: guard debug engine id access during initialization X-Git-Url: https://git.kaiwu.me/ngx_http_auth_basic_module.html?a=commitdiff_plain;h=cb939f1078f629c19626ed85b837038ea000f042;p=njs.git Modules: guard debug engine id access during initialization The request engine is not published while global code runs. Reading ngx.engine_id at that point dereferenced NULL instead of reporting that the debug property is unavailable. Reject the access in both engines without publishing a partial clone. --- diff --git a/nginx/ngx_js.c b/nginx/ngx_js.c index 282af631..5101d92a 100644 --- a/nginx/ngx_js.c +++ b/nginx/ngx_js.c @@ -1991,6 +1991,11 @@ ngx_qjs_ext_engine_id(JSContext *cx, JSValueConst this_val) external = JS_GetContextOpaque(cx); ctx = ngx_qjs_external_ctx(cx, external); + if (ctx->engine == NULL) { + return JS_ThrowTypeError(cx, "engine is not available " + "during module initialization"); + } + return JS_NewUint32(cx, ctx->engine->id); } #endif @@ -3007,6 +3012,12 @@ ngx_js_ext_engine_id(njs_vm_t *vm, njs_object_prop_t *prop, uint32_t unused, ctx = ngx_external_ctx(vm, njs_vm_external_ptr(vm)); + if (ctx->engine == NULL) { + njs_vm_type_error(vm, "engine is not available " + "during module initialization"); + return NJS_ERROR; + } + njs_value_number_set(retval, ctx->engine->id); return NJS_OK; }