From e6c25e84bc662797c7382500f136bb74874c2500 Mon Sep 17 00:00:00 2001 From: Luka Krajger Date: Mon, 6 Jun 2016 16:11:11 +0200 Subject: [PATCH] Issue #381: Fixed segfaults at logging * This patch correctly handles varargs being used two times in the same function. --- logging/logging.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/logging/logging.c b/logging/logging.c index a06d783..4c24334 100644 --- a/logging/logging.c +++ b/logging/logging.c @@ -100,7 +100,11 @@ void error(const char *fmt, ...) { va_start(ap, fmt); debugMsg(MSG_ERROR, fmt, ap); #ifdef HAVE_SYSLOG_H - vsyslog(LOG_ERR, fmt, ap); + va_list apSyslog; + va_copy(apSyslog, ap); + va_start(apSyslog, fmt); + vsyslog(LOG_ERR, fmt, apSyslog); + va_end(apSyslog); #endif va_end(ap); } @@ -117,7 +121,11 @@ void fatal(const char *fmt, ...) { va_start(ap, fmt); debugMsg(MSG_QUIET, fmt, ap); #ifdef HAVE_SYSLOG_H - vsyslog(LOG_CRIT, fmt, ap); + va_list apSyslog; + va_copy(apSyslog, ap); + va_start(apSyslog, fmt); + vsyslog(LOG_CRIT, fmt, apSyslog); + va_end(apSyslog); syslog(LOG_CRIT, "[server] Aborting..."); #endif va_end(ap);