aboutsummaryrefslogtreecommitdiff
path: root/lib/sendf.c
diff options
context:
space:
mode:
authorDaniel Gustafsson <daniel@yesql.se>2018-11-03 20:54:18 +0100
committerDaniel Gustafsson <daniel@yesql.se>2018-11-03 20:54:18 +0100
commitc37b66aaaed0a36bcb1b19596e897d7ac6219611 (patch)
treeba305dc3d11d1e3b07ca699d19c88f1a95e0c2ab /lib/sendf.c
parentd82a17ad850914fee6dd17aadf9c5f902cda599f (diff)
infof: clearly indicate truncation
The internal buffer in infof() is limited to 2048 bytes of payload plus an additional byte for NULL termination. Servers with very long error messages can however cause truncation of the string, which currently isn't very clear, and leads to badly formatted output. This appends a "...\n" (or just "..." in case the format didn't with a newline char) marker to the end of the string to clearly show that it has been truncated. Also include a unittest covering infof() to try and catch any bugs introduced in this quite important function. Closes #3216 Reviewed-by: Daniel Stenberg <daniel@haxx.se> Reviewed-by: Marcel Raad <Marcel.Raad@teamviewer.com>
Diffstat (limited to 'lib/sendf.c')
-rw-r--r--lib/sendf.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/sendf.c b/lib/sendf.c
index d3c10b369..77eacdf5f 100644
--- a/lib/sendf.c
+++ b/lib/sendf.c
@@ -237,7 +237,18 @@ void Curl_infof(struct Curl_easy *data, const char *fmt, ...)
size_t len;
char print_buffer[2048 + 1];
va_start(ap, fmt);
- vsnprintf(print_buffer, sizeof(print_buffer), fmt, ap);
+ len = vsnprintf(print_buffer, sizeof(print_buffer), fmt, ap);
+ /*
+ * Indicate truncation of the input by replacing the last 3 characters
+ * with "...", and transfer the newline over in case the format had one.
+ */
+ if(len >= sizeof(print_buffer)) {
+ len = strlen(fmt);
+ if(fmt[--len] == '\n')
+ snprintf(print_buffer + (sizeof(print_buffer) - 5), 5, "...\n");
+ else
+ snprintf(print_buffer + (sizeof(print_buffer) - 4), 4, "...");
+ }
va_end(ap);
len = strlen(print_buffer);
Curl_debug(data, CURLINFO_TEXT, print_buffer, len);