Handle vsnprintf overflows (Thanks Han)
This commit is contained in:
parent
9a46335e25
commit
68544a519e
|
@ -194,9 +194,15 @@ static void vlog(const bool print, const char *fmt, va_list args) {
|
||||||
vprintf(fmt, args);
|
vprintf(fmt, args);
|
||||||
} else {
|
} else {
|
||||||
len += vsnprintf(message + len, sizeof(message) - len, fmt, args);
|
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");
|
fprintf(stderr, "BUG: single log message > 4k\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If there is no space for the current message (plus trailing
|
/* If there is no space for the current message (plus trailing
|
||||||
* nullbyte) in the ringbuffer, we need to wrap and write to the
|
* nullbyte) in the ringbuffer, we need to wrap and write to the
|
||||||
* beginning again. */
|
* beginning again. */
|
||||||
|
|
Loading…
Reference in New Issue