[njs] Fixed absolute scope in cloned VMs.

noreply at nginx.com noreply at nginx.com
Fri Nov 22 18:54:02 UTC 2024


details:   https://github.com/nginx/njs/commit/11c36e925bc63633f8ca39ee2f237cc13fe5519d
branches:  master
commit:    11c36e925bc63633f8ca39ee2f237cc13fe5519d
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Wed, 13 Nov 2024 21:14:34 -0800
description:
Fixed absolute scope in cloned VMs.


---
 src/njs_vm.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/njs_vm.c b/src/njs_vm.c
index 908c40c8..90428cb4 100644
--- a/src/njs_vm.c
+++ b/src/njs_vm.c
@@ -384,7 +384,7 @@ njs_vm_clone(njs_vm_t *vm, njs_external_ptr_t external)
     njs_mp_t     *nmp;
     njs_vm_t     *nvm;
     njs_int_t    ret;
-    njs_value_t  **global;
+    njs_value_t  **global, **value;
 
     njs_thread_log_debug("CLONE:");
 
@@ -423,6 +423,24 @@ njs_vm_clone(njs_vm_t *vm, njs_external_ptr_t external)
         goto fail;
     }
 
+    if (nvm->options.unsafe) {
+        nvm->scope_absolute = njs_arr_create(nvm->mem_pool,
+                                             vm->scope_absolute->items,
+                                             sizeof(njs_value_t *));
+        if (njs_slow_path(nvm->scope_absolute == NULL)) {
+            goto fail;
+        }
+
+        value = njs_arr_add_multiple(nvm->scope_absolute,
+                                     vm->scope_absolute->items);
+        if (njs_slow_path(value == NULL)) {
+            goto fail;
+        }
+
+        memcpy(value, vm->scope_absolute->start,
+               vm->scope_absolute->items * sizeof(njs_value_t *));
+    }
+
     nvm->levels[NJS_LEVEL_GLOBAL] = global;
 
     /* globalThis and this */


More information about the nginx-devel mailing list