[njs] Modules: adding NUL byte at the end of the module body.

noreply at nginx.com noreply at nginx.com
Sat Jun 29 02:53:07 UTC 2024


details:   https://hg.nginx.org/njs/rev/818ab94037d7
branches:  
changeset: 2364:818ab94037d7
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Tue Jun 18 23:47:31 2024 -0700
description:
Modules: adding NUL byte at the end of the module body.

Even though QuickJS takes length as an argument, when parsing the code,
it expects NUL byte at the end.

diffstat:

 nginx/ngx_js.c |  4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diffs (21 lines):

diff -r f358df45922c -r 818ab94037d7 nginx/ngx_js.c
--- a/nginx/ngx_js.c	Fri Jun 21 17:58:32 2024 -0700
+++ b/nginx/ngx_js.c	Tue Jun 18 23:47:31 2024 -0700
@@ -1841,7 +1841,7 @@ ngx_js_module_read(njs_mp_t *mp, int fd,
 
     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,
         goto fail;
     }
 
+    text->start[text->length] = '\0';
+
     return NJS_OK;
 
 fail:


More information about the nginx-devel mailing list