From 73b0fdabdb108880034b7730d04614d8a7cf943a Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 21 Aug 2020 11:28:08 +0200 Subject: [PATCH] common: Strip trailing CR,LF from w32_strerror. * common/stringhelp.c (w32_strerror): Strip trailing CR,LF. * common/iobuf.c (iobuf_get_filelength): Use -1 and not 0 for the arg to w32_strerror. -- This is in particular annoying since we started to use a string argument sanitizer in the logging code. Before that we just add an extra blank line. The second patch corrects a never yet seen error message. Signed-off-by: Werner Koch --- common/iobuf.c | 2 +- common/stringhelp.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/common/iobuf.c b/common/iobuf.c index efbf21cbc..b20761ba1 100644 --- a/common/iobuf.c +++ b/common/iobuf.c @@ -2335,7 +2335,7 @@ iobuf_get_filelength (iobuf_t a, int *overflow) return size; } log_error ("GetFileSize for handle %p failed: %s\n", - fp, w32_strerror (0)); + fp, w32_strerror (-1)); #else /*!HAVE_W32_SYSTEM*/ { struct stat st; diff --git a/common/stringhelp.c b/common/stringhelp.c index 7d5b5f806..babdeb847 100644 --- a/common/stringhelp.c +++ b/common/stringhelp.c @@ -789,6 +789,12 @@ w32_strerror (int ec) FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, ec, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), strerr, DIM (strerr)-1, NULL); + { + /* Strip the CR,LF - we want just the string. */ + size_t n = strlen (strerr); + if (n > 2 && strerr[n-2] == '\r' && strerr[n-1] == '\n' ) + strerr[n-2] = 0; + } #endif return strerr; }