From: Daris A Nevil Date: Tue, 18 Feb 2020 14:26:06 +0000 (+0000) Subject: Remove 8K limit for single access.log line (#332) X-Git-Tag: 4.15-20210522-snapshot~166 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a03343c2acbc382a59a176713d5e33387b82f6a9;p=thirdparty%2Fsquid.git Remove 8K limit for single access.log line (#332) 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. --- diff --git a/src/log/File.cc b/src/log/File.cc index 42a873909c..36cf4ca3c4 100644 --- a/src/log/File.cc +++ b/src/log/File.cc @@ -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); } diff --git a/src/log/File.h b/src/log/File.h index cc4ff9c049..5f034fb79a 100644 --- a/src/log/File.h +++ b/src/log/File.h @@ -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);