From: Michael Stapelberg Date: Fri, 30 Dec 2011 00:25:50 +0000 (+0100) Subject: Handle vsnprintf overflows (Thanks Han) X-Git-Tag: 4.2~163 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=68544a519ea2d73bbbd03ca8fc0abcd6798e3cd3;p=i3%2Fi3 Handle vsnprintf overflows (Thanks Han) --- diff --git a/src/log.c b/src/log.c index 05a235fa..14819e9e 100644 --- a/src/log.c +++ b/src/log.c @@ -194,9 +194,15 @@ static void vlog(const bool print, const char *fmt, va_list args) { vprintf(fmt, args); } else { len += vsnprintf(message + len, sizeof(message) - len, fmt, args); - if (len == sizeof(message)) { + if (len < 0 ) { + fprintf(stderr, "BUG: something is overflowing here. Dropping the log entry\n"); + return; + } + + if (len >= sizeof(message)) { fprintf(stderr, "BUG: single log message > 4k\n"); } + /* If there is no space for the current message (plus trailing * nullbyte) in the ringbuffer, we need to wrap and write to the * beginning again. */