details: https://github.com/nginx/njs/commit/b6d108c812c07b11d4c3f65a48a5898139ac1ae4 branches: master commit: b6d108c812c07b11d4c3f65a48a5898139ac1ae4 user: Dmitry Volyntsev <xei...@nginx.com> date: Wed, 12 Feb 2025 19:11:08 -0800 description: QuickJS: fixed non-NULL terminated strings formatting in exceptions.
When "%*s" is specified, the first integer is interpreted as width. Width specifies *minimum* number of characters to output. The next string is expected to be NULL-terminated. When "%.*s" is specified, the first integer is interpreted as precision. Precision specifies *maximum* number of characters to output. --- external/njs_shell.c | 6 +++--- external/qjs_webcrypto_module.c | 2 +- nginx/ngx_js.c | 4 ++-- nginx/ngx_stream_js_module.c | 2 +- src/qjs_buffer.c | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/external/njs_shell.c b/external/njs_shell.c index 776c2536..015c930f 100644 --- a/external/njs_shell.c +++ b/external/njs_shell.c @@ -2590,7 +2590,7 @@ njs_qjs_module_loader(JSContext *ctx, const char *module_name, void *opaque) (void) close(info.fd); if (njs_slow_path(ret != NJS_OK)) { - JS_ThrowInternalError(ctx, "while reading \"%*s\" module", + JS_ThrowInternalError(ctx, "while reading \"%.*s\" module", (int) info.file.length, info.file.start); return NULL; } @@ -2599,7 +2599,7 @@ njs_qjs_module_loader(JSContext *ctx, const char *module_name, void *opaque) ret = njs_console_set_cwd(console, &info.file); if (njs_slow_path(ret != NJS_OK)) { - JS_ThrowInternalError(ctx, "while setting cwd for \"%*s\" module", + JS_ThrowInternalError(ctx, "while setting cwd for \"%.*s\" module", (int) info.file.length, info.file.start); return NULL; } @@ -2827,7 +2827,7 @@ njs_engine_qjs_unhandled_rejection(njs_engine_t *engine) return -1; } - JS_ThrowTypeError(ctx, "unhandled promise rejection: %*s", (int) len, str); + JS_ThrowTypeError(ctx, "unhandled promise rejection: %.*s", (int) len, str); JS_FreeCString(ctx, str); for (i = 0; i < console->rejected_promises->items; i++) { diff --git a/external/qjs_webcrypto_module.c b/external/qjs_webcrypto_module.c index 64098f4e..cc654c0a 100644 --- a/external/qjs_webcrypto_module.c +++ b/external/qjs_webcrypto_module.c @@ -4802,7 +4802,7 @@ qjs_webcrypto_error(JSContext *cx, const char *fmt, ...) } } - JS_ThrowTypeError(cx, "%*s", (int) (p - errstr), errstr); + JS_ThrowTypeError(cx, "%.*s", (int) (p - errstr), errstr); } diff --git a/nginx/ngx_js.c b/nginx/ngx_js.c index 5c2a44cb..7f7b7362 100644 --- a/nginx/ngx_js.c +++ b/nginx/ngx_js.c @@ -1988,7 +1988,7 @@ ngx_qjs_module_loader(JSContext *cx, const char *module_name, void *opaque) (void) close(info.fd); if (ret != NJS_OK) { - JS_ThrowInternalError(cx, "while reading \"%*s\" module", + JS_ThrowInternalError(cx, "while reading \"%.*s\" module", (int) info.file.length, info.file.start); return NULL; } @@ -2057,7 +2057,7 @@ ngx_qjs_unhandled_rejection(ngx_js_ctx_t *ctx) return -1; } - JS_ThrowTypeError(cx, "unhandled promise rejection: %*s", (int) len, str); + JS_ThrowTypeError(cx, "unhandled promise rejection: %.*s", (int) len, str); JS_FreeCString(cx, str); for (i = 0; i < ctx->rejected_promises->items; i++) { diff --git a/nginx/ngx_stream_js_module.c b/nginx/ngx_stream_js_module.c index a7a923ad..59a3e9d2 100644 --- a/nginx/ngx_stream_js_module.c +++ b/nginx/ngx_stream_js_module.c @@ -2126,7 +2126,7 @@ ngx_stream_qjs_event(ngx_stream_session_t *s, JSContext *cx, ngx_str_t *event) } if (i == n) { - (void) JS_ThrowInternalError(cx, "unknown event \"%*s\"", + (void) JS_ThrowInternalError(cx, "unknown event \"%.*s\"", (int) event->len, event->data); return NULL; } diff --git a/src/qjs_buffer.c b/src/qjs_buffer.c index 8fc296ad..638d273c 100644 --- a/src/qjs_buffer.c +++ b/src/qjs_buffer.c @@ -2099,7 +2099,7 @@ qjs_buffer_encoding(JSContext *ctx, JSValueConst value, JS_BOOL thrw) JS_FreeCString(ctx, (char *) name.start); if (thrw) { - JS_ThrowTypeError(ctx, "\"%*s\" encoding is not supported", + JS_ThrowTypeError(ctx, "\"%.*s\" encoding is not supported", (int) name.length, name.start); } _______________________________________________ nginx-devel mailing list nginx-devel@nginx.org https://mailman.nginx.org/mailman/listinfo/nginx-devel