log: check for i/o error with vsnprintf()

parent a760603e
......@@ -264,7 +264,7 @@ static int log_append_logfile(const struct lxc_log_appender *appender,
{
char buffer[LXC_LOG_BUFFER_SIZE];
char date_time[LXC_LOG_TIME_SIZE];
int n;
int n, ret;
int fd_to_use = -1;
#ifndef NO_LXC_CONF
......@@ -295,8 +295,13 @@ static int log_append_logfile(const struct lxc_log_appender *appender,
if (n < 0)
return n;
if ((size_t)n < (sizeof(buffer) - 1))
n += vsnprintf(buffer + n, sizeof(buffer) - n, event->fmt, *event->vap);
if ((size_t)n < (sizeof(buffer) - 1)) {
ret = vsnprintf(buffer + n, sizeof(buffer) - n, event->fmt, *event->vap);
if (ret < 0)
return 0;
n += ret;
}
if ((size_t)n >= sizeof(buffer))
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