From 0abc53ecc7caaa55cc780a0424a64055c46bde36 Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Tue, 18 Jun 2024 23:47:31 -0700 Subject: [PATCH] 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. --- nginx/ngx_js.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nginx/ngx_js.c b/nginx/ngx_js.c index aa5e71cc6..5387ba130 100644 --- a/nginx/ngx_js.c +++ b/nginx/ngx_js.c @@ -1847,7 +1847,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; } @@ -1858,6 +1858,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: