]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Log: Fix broken syslog name
authorOndrej Zajicek (work) <santiago@crfreenet.org>
Tue, 1 Nov 2016 10:37:49 +0000 (11:37 +0100)
committerOndrej Zajicek (work) <santiago@crfreenet.org>
Tue, 1 Nov 2016 10:37:49 +0000 (11:37 +0100)
BIRD passed string from configuration to openlog(), which kept it
internally. After reconfiguration the old string was freed, therefore
openlog had invalid copy.

Thanks to Chris Caputo for the original patch.

lib/string.h
sysdep/unix/log.c

index 9af49b9ee5427e31bdcf79efb2191b3fca4d2117..bf0b7cb07c64c97971205e785a5cea718c44cb0b 100644 (file)
@@ -30,6 +30,15 @@ static inline char *xbasename(const char *str)
   return s ? s+1 : (char *) str;
 }
 
+static inline char *
+xstrdup(const char *c)
+{
+  size_t l = strlen(c) + 1;
+  char *z = xmalloc(l);
+  memcpy(z, c, l);
+  return z;
+}
+
 #define ROUTER_ID_64_LENGTH 23
 
 #endif
index 1fd64426588cd85f568d0b4507b768fdaeed287c..b89e6b7a06172d990b274505acbafb0d7a41c6ad 100644 (file)
@@ -288,18 +288,22 @@ log_switch(int debug, list *l, char *new_syslog_name)
   current_log_list = l;
 
 #ifdef HAVE_SYSLOG
-  char *old_syslog_name = current_syslog_name;
-  current_syslog_name = new_syslog_name;
-
-  if (old_syslog_name && new_syslog_name &&
-      !strcmp(old_syslog_name, new_syslog_name))
+  if (current_syslog_name && new_syslog_name &&
+      !strcmp(current_syslog_name, new_syslog_name))
     return;
 
-  if (old_syslog_name)
+  if (current_syslog_name)
+  {
     closelog();
+    xfree(current_syslog_name);
+    current_syslog_name = NULL;
+  }
 
   if (new_syslog_name)
-    openlog(new_syslog_name, LOG_CONS | LOG_NDELAY, LOG_DAEMON);
+  {
+    current_syslog_name = xstrdup(new_syslog_name);
+    openlog(current_syslog_name, LOG_CONS | LOG_NDELAY, LOG_DAEMON);
+  }
 #endif
 }