]> git.kaiwu.me - njs.git/commitdiff
Modules: adding NUL byte at the end of the module body.
authorDmitry Volyntsev <xeioex@nginx.com>
Wed, 19 Jun 2024 06:47:31 +0000 (23:47 -0700)
committerDmitry Volyntsev <xeioexception@gmail.com>
Sat, 29 Jun 2024 02:52:47 +0000 (19:52 -0700)
Even though QuickJS takes length as an argument, when parsing the code,
it expects NUL byte at the end.

nginx/ngx_js.c

index ef85096cc18e8fc588bdf6a08c2f94e7088dd8eb..b372feca984506d2450408f54b7fb56c48777985 100644 (file)
@@ -1841,7 +1841,7 @@ ngx_js_module_read(njs_mp_t *mp, int fd, njs_str_t *text)
 
     text->length = sb.st_size;
 
-    text->start = njs_mp_alloc(mp, text->length);
+    text->start = njs_mp_alloc(mp, text->length + 1);
     if (text->start == NULL) {
         goto fail;
     }
@@ -1852,6 +1852,8 @@ ngx_js_module_read(njs_mp_t *mp, int fd, njs_str_t *text)
         goto fail;
     }
 
+    text->start[text->length] = '\0';
+
     return NJS_OK;
 
 fail: