From ca33d2f5bfba3ca122124aea571859a9dc2bb234 Mon Sep 17 00:00:00 2001
From: Andy Green <andy@warmcat.com>
Date: Sun, 2 Sep 2018 07:13:56 +0800
Subject: [PATCH] logging: ellipsisize logs longer than our line buffer

Currently the line buffer for vsnprintf() is 256, lines longer than that
end abruptly without a CRLF.

Change it to end with "...\n\0" when it truncates the line.

CSP header additions, logged on vhost init, longer than this are going
to become normal...
---
 lib/core/libwebsockets.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/lib/core/libwebsockets.c b/lib/core/libwebsockets.c
index 2bcd015e..b3a83140 100644
--- a/lib/core/libwebsockets.c
+++ b/lib/core/libwebsockets.c
@@ -2066,8 +2066,14 @@ LWS_VISIBLE void _lws_logv(int filter, const char *format, va_list vl)
 	n = vsnprintf(buf, sizeof(buf) - 1, format, vl);
 	(void)n;
 	/* vnsprintf returns what it would have written, even if truncated */
-	if (n > (int)sizeof(buf) - 1)
-		n = sizeof(buf) - 1;
+	if (n > (int)sizeof(buf) - 1) {
+		n = sizeof(buf) - 5;
+		buf[n++] = '.';
+		buf[n++] = '.';
+		buf[n++] = '.';
+		buf[n++] = '\n';
+		buf[n] = '\0';
+	}
 	if (n > 0)
 		buf[n] = '\0';
 
-- 
GitLab