Commit dff34a76 by Lans Zhang Committed by Stéphane Graber

log: sanity check the returned value from snprintf()

The returned value from snprintf() should be checked carefully. This bug can be leveraged to execute arbitrary code through carefully constructing the payload, e.g, lxc-freeze -n `python -c "print 'AAAAAAAA' + 'B'*959"` -P PADPAD -o /tmp/log This command running on Ubuntu 14.04 (x86-64) can cause a segment fault. Signed-off-by: 's avatarLans Zhang <jia.zhang@windriver.com>
parent 957edbf8
...@@ -101,10 +101,13 @@ static int log_append_logfile(const struct lxc_log_appender *appender, ...@@ -101,10 +101,13 @@ static int log_append_logfile(const struct lxc_log_appender *appender,
event->locinfo->file, event->locinfo->func, event->locinfo->file, event->locinfo->func,
event->locinfo->line); event->locinfo->line);
n += vsnprintf(buffer + n, sizeof(buffer) - n, event->fmt, if (n < 0)
*event->vap); 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, WARN("truncated next event from %d to %zd bytes", n,
sizeof(buffer)); sizeof(buffer));
n = sizeof(buffer) - 1; n = sizeof(buffer) - 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment