]> git.kaiwu.me - njs.git/commitdiff
Modules: guard debug engine id access during initialization
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 5 Nov 2026 00:49:38 +0000 (16:49 -0800)
committerDmitry Volyntsev <xeioexception@gmail.com>
Wed, 11 Nov 2026 21:33:45 +0000 (13:33 -0800)
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.

nginx/ngx_js.c

index 282af63185bc46e397b84da9a9c79b9f7be3170f..5101d92afe7d7dba943afcdde08bce639ac27b76 100644 (file)
@@ -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;
 }