From 68ce971c1d02a07cc6353cb4afbd47257b3f9104 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 12 Apr 2024 10:57:02 +0200 Subject: [PATCH] mbedtls: cut off trailing newlines from debug logs To avoid double newlines in the output. Reported-by: Gisle Vanem Fixes #13321 Closes #13356 --- lib/vtls/mbedtls.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/vtls/mbedtls.c b/lib/vtls/mbedtls.c index 4967beac36..a70a6b6fe0 100644 --- a/lib/vtls/mbedtls.c +++ b/lib/vtls/mbedtls.c @@ -163,15 +163,18 @@ static int entropy_func_mutex(void *data, unsigned char *output, size_t len) static void mbed_debug(void *context, int level, const char *f_name, int line_nb, const char *line) { - struct Curl_easy *data = NULL; - - if(!context) - return; - - data = (struct Curl_easy *)context; - - infof(data, "%s", line); + struct Curl_easy *data = (struct Curl_easy *)context; (void) level; + (void) line_nb; + (void) f_name; + + if(data) { + size_t len = strlen(line); + if(len && (line[len - 1] == '\n')) + /* discount any trailing newline */ + len--; + infof(data, "%.*s", (int)len, line); + } } #endif