]> git.kaiwu.me - njs.git/commitdiff
Modules: adding NUL byte at the end of the global script.
authorDmitry Volyntsev <xeioex@nginx.com>
Fri, 26 Jul 2024 02:02:35 +0000 (19:02 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Fri, 16 Aug 2024 15:26:45 +0000 (08:26 -0700)
Even though QuickJS takes length as an argument, when parsing the code,
it expects NUL byte at the end.

This change is similar to 184d2a39cb5 (0.8.5).

nginx/ngx_js.c

index b372feca984506d2450408f54b7fb56c48777985..9a20a6848e507563cc1e8a748b15fceebde9a755 100644 (file)
@@ -2017,7 +2017,7 @@ ngx_js_init_conf_vm(ngx_conf_t *cf, ngx_js_loc_conf_t *conf,
                 + sizeof(" globalThis. = ;\n") - 1;
     }
 
-    start = ngx_pnalloc(cf->pool, size);
+    start = ngx_pnalloc(cf->pool, size + 1);
     if (start == NULL) {
         return NGX_ERROR;
     }
@@ -2039,6 +2039,8 @@ ngx_js_init_conf_vm(ngx_conf_t *cf, ngx_js_loc_conf_t *conf,
         p = ngx_cpymem(p, ";\n", sizeof(";\n") - 1);
     }
 
+    *p = '\0';
+
     file = ngx_cycle->conf_prefix;
 
     options->file.start = file.data;