[SSSD] [PATCH] sss_log: fix handling of variable argument lists

Sumit Bose sbose at redhat.com
Tue Aug 26 15:44:38 UTC 2014


Hi,

this patch fixes a issue with sss_log() which was introduced recently
and I think is only in master. So far I only tested it with syslog, if
would be nice if someone can test the journald code path as well.

bye,
Sumit
-------------- next part --------------
From cb4a1788cc8d4fd4251de2ee83ff760b740a68d6 Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose at redhat.com>
Date: Tue, 26 Aug 2014 17:29:08 +0200
Subject: [PATCH] sss_log: fix handling of variable argument lists

SSSD has two public calls to send messages to syslog sss_log() and
sss_log_ext() which both expect besides other arguments a printf format
string and a variable list of arguments depending on the format.
Currently sss_log() calls sss_log_ext() internally after calling
va_start(ap, format) and hands over ap as the last argument. This does
not work because there is a difference between a varying number of
arguments and a va_list type.

To fix this I added a new private call which expects a va_list as the
last argument and is called by sss_log() and sss_log_ext() after calling
va_start().
---
 src/util/sss_log.c | 28 +++++++++++++++++++---------
 1 file changed, 19 insertions(+), 9 deletions(-)

diff --git a/src/util/sss_log.c b/src/util/sss_log.c
index 7a2dce6..b0c3f99 100644
--- a/src/util/sss_log.c
+++ b/src/util/sss_log.c
@@ -57,28 +57,40 @@ static int sss_to_syslog(int priority)
     }
 }
 
+static void sss_log_ext_int(int priority, int facility, const char *format,
+                            va_list ap);
+
 void sss_log(int priority, const char *format, ...)
 {
     va_list ap;
 
     va_start(ap, format);
-    sss_log_ext(priority, LOG_DAEMON, format, ap);
+    sss_log_ext_int(priority, LOG_DAEMON, format, ap);
     va_end(ap);
 }
 
-#ifdef WITH_JOURNALD
-
 void sss_log_ext(int priority, int facility, const char *format, ...)
 {
     va_list ap;
+
+    va_start(ap, format);
+    sss_log_ext_int(priority, facility, format, ap);
+    va_end(ap);
+}
+
+
+
+#ifdef WITH_JOURNALD
+
+static void sss_log_ext_int(int priority, int facility, const char *format,
+                            va_list ap)
+{
     int syslog_priority;
     int ret;
     char *message;
     const char *domain;
 
-    va_start(ap, format);
     ret = vasprintf(&message, format, ap);
-    va_end(ap);
 
     if (ret == -1) {
         /* ENOMEM */
@@ -103,18 +115,16 @@ void sss_log_ext(int priority, int facility, const char *format, ...)
 
 #else /* WITH_JOURNALD */
 
-void sss_log_ext(int priority, int facility, const char *format, ...)
+static void sss_log_ext_int(int priority, int facility, const char *format,
+                            va_list ap)
 {
-    va_list ap;
     int syslog_priority;
 
     syslog_priority = sss_to_syslog(priority);
 
     openlog(debug_prg_name, 0, facility);
 
-    va_start(ap, format);
     vsyslog(syslog_priority, format, ap);
-    va_end(ap);
 
     closelog();
 }
-- 
1.8.3.1



More information about the sssd-devel mailing list