]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Remove 8K limit for single access.log line (#332)
authorDaris A Nevil <daris@nevil.org>
Tue, 18 Feb 2020 14:26:06 +0000 (14:26 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Tue, 18 Feb 2020 18:35:32 +0000 (18:35 +0000)
The function logfilePrintf() currently limits a single line
to no more than 8K characters.  It allocates an 8K buffer
on the stack, which is not safe. This PR eliminates
the 8K limit, and moves the buffer to the heap.

src/log/File.cc
src/log/File.h

index 42a873909c9f7aa79caefbfeb40d0aa32b877d30..36cf4ca3c4d7383cc702d0723c7b958d0a1068c3 100644 (file)
@@ -17,6 +17,7 @@
 #include "log/ModSyslog.h"
 #include "log/ModUdp.h"
 #include "log/TcpLogger.h"
+#include "sbuf/SBuf.h"
 
 CBDATA_CLASS_INIT(Logfile);
 
@@ -103,7 +104,7 @@ logfileRotate(Logfile * lf, int16_t rotateCount)
 }
 
 void
-logfileWrite(Logfile * lf, char *buf, size_t len)
+logfileWrite(Logfile * lf, const char *buf, size_t len)
 {
     lf->f_linewrite(lf, buf, len);
 }
@@ -112,21 +113,11 @@ void
 logfilePrintf(Logfile * lf, const char *fmt,...)
 {
     va_list args;
-    char buf[8192];
-    int s;
-
     va_start(args, fmt);
-
-    s = vsnprintf(buf, 8192, fmt, args);
-
-    if (s > 8192) {
-        s = 8192;
-
-        if (fmt[strlen(fmt) - 1] == '\n')
-            buf[8191] = '\n';
-    }
-
-    logfileWrite(lf, buf, (size_t) s);
+    static SBuf sbuf;
+    sbuf.clear();
+    sbuf.vappendf(fmt, args); // Throws on overflow. TODO: handle that better
+    logfileWrite(lf, sbuf.c_str(), sbuf.length());
     va_end(args);
 }
 
index cc4ff9c049ab9b29dde189a8768efc0b643ff81d..5f034fb79ac11c90263da810ddca0abd54210338 100644 (file)
@@ -66,7 +66,7 @@ public:
 Logfile *logfileOpen(const char *path, size_t bufsz, int);
 void logfileClose(Logfile * lf);
 void logfileRotate(Logfile * lf, int16_t rotateCount);
-void logfileWrite(Logfile * lf, char *buf, size_t len);
+void logfileWrite(Logfile * lf, const char *buf, size_t len);
 void logfileFlush(Logfile * lf);
 void logfilePrintf(Logfile * lf, const char *fmt,...) PRINTF_FORMAT_ARG2;
 void logfileLineStart(Logfile * lf);