]> git.kaiwu.me - njs.git/commitdiff
QuickJS: fixed non-NULL terminated strings formatting in exceptions.
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 13 Feb 2025 03:11:08 +0000 (19:11 -0800)
committerDmitry Volyntsev <xeioexception@gmail.com>
Wed, 19 Feb 2025 00:30:00 +0000 (16:30 -0800)
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
external/qjs_webcrypto_module.c
nginx/ngx_js.c
nginx/ngx_stream_js_module.c
src/qjs_buffer.c

index 776c2536bd6a1aa899fc7b9ccb22f2e932999293..015c930f1d06ace5fe2b5a826ac0359543f6b216 100644 (file)
@@ -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++) {
index 64098f4e10bd941bc4fc017c276968b6a3799852..cc654c0ac7981a3adc084af36427ed7a7e5b287f 100644 (file)
@@ -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);
 }
 
 
index 5c2a44cb0d5b2b67f079c7c08a8360b8ef98b722..7f7b736223533d9a8700abd9de74bb9f1ff635f3 100644 (file)
@@ -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++) {
index a7a923ad256a7f3f7daf65a5ca6753d7d9ebea3d..59a3e9d22684d8e054020adf7faba5f80ae80b53 100644 (file)
@@ -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;
     }
index 8fc296ad88c0655389237b0fe9c2a43040f0c703..638d273c63275752fd23fc0c0922f047089c9b7f 100644 (file)
@@ -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);
     }