From: Dmitry Volyntsev Date: Thu, 12 Nov 2026 04:04:23 +0000 (-0800) Subject: VM: fix call stack sharing in cloned VMs X-Git-Url: https://git.kaiwu.me/http/ngx_http_auth_basic_module.html?a=commitdiff_plain;h=67b31155c79297de3219eb405e8b9807a7e63463;p=njs.git VM: fix call stack sharing in cloned VMs Previously, njs_vm_clone() copied the call stack pointers of the VM being cloned. A VM created with the "init" option keeps its initial frame, so every clone allocated frames in the spare space of that frame instead of its own memory. When two clones of the same VM ran at the same time, they overwrote each other's frames. In nginx, this happened when a parent handler evaluated a js_set variable of a subrequest: the subrequest clone overwrote the frames of the running parent clone, which crashed after returning from the native call. Now a cloned VM starts with an empty call stack and allocates its own initial frame. The issue was introduced in 16f42c87 (0.8.8). --- diff --git a/src/njs_vm.c b/src/njs_vm.c index 6bd459f1..ed98c467 100644 --- a/src/njs_vm.c +++ b/src/njs_vm.c @@ -442,6 +442,9 @@ njs_vm_clone(njs_vm_t *vm, njs_external_ptr_t external) nvm->trace.data = nvm; nvm->external = external; + nvm->active_frame = NULL; + nvm->top_frame = NULL; + nvm->shared_atom_count = vm->atom_id_generator; njs_flathsh_init(&nvm->atom_hash);