Skip to content

Commit

Permalink
Remove 8K limit for single access.log line (#332)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
redmeadowman authored and squid-anubis committed Feb 18, 2020
1 parent 395d284 commit a03343c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 16 deletions.
21 changes: 6 additions & 15 deletions src/log/File.cc
Expand Up @@ -17,6 +17,7 @@
#include "log/ModSyslog.h"
#include "log/ModUdp.h"
#include "log/TcpLogger.h"
#include "sbuf/SBuf.h"

CBDATA_CLASS_INIT(Logfile);

Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/log/File.h
Expand Up @@ -66,7 +66,7 @@ class Logfile
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);
Expand Down

0 comments on commit a03343c

Please sign in to comment.