2
0
mirror of git://github.com/lxc/lxc synced 2025-08-29 19:59:51 +00:00

Merge pull request #1225 from jiazhang0/master

log: sanity check the returned value from snprintf()
This commit is contained in:
Christian Brauner 2016-10-12 11:49:57 +02:00 committed by GitHub
commit aa74ed7b96

View File

@ -170,10 +170,13 @@ static int log_append_logfile(const struct lxc_log_appender *appender,
event->locinfo->file, event->locinfo->func,
event->locinfo->line);
n += vsnprintf(buffer + n, sizeof(buffer) - n, event->fmt,
*event->vap);
if (n < 0)
return n;
if (n >= sizeof(buffer) - 1) {
if (n < sizeof(buffer) - 1)
n += vsnprintf(buffer + n, sizeof(buffer) - n, event->fmt,
*event->vap);
else {
WARN("truncated next event from %d to %zd bytes", n,
sizeof(buffer));
n = sizeof(buffer) - 1;