[PATCH] fix syslog corruption when using customized name
Chris Caputo
ccaputo at alt.net
Mon Oct 31 16:27:48 CET 2016
On Mon, 31 Oct 2016, Ondrej Zajicek wrote:
> On Sun, Oct 30, 2016 at 10:40:30PM +0000, Chris Caputo wrote:
> > Fix bug with syslog using string passed to openlog() which is later
> > stomped on, resulting in corrupted log messages. This happens when name
> > is specified in a syslog log line, ala:
>
> Thanks, you are right. I will merge the patch.
>
> Note that there is a minor bug in the patch as the current_syslog_name
> is not updated when new_syslog_name == NULL.
Ack - thank you for catching that. Is this better?
Thanks,
Chris
diff --git a/sysdep/unix/log.c b/sysdep/unix/log.c
index 1fd6442..89eae01 100644
--- a/sysdep/unix/log.c
+++ b/sysdep/unix/log.c
@@ -289,17 +289,27 @@ log_switch(int debug, list *l, char *new_syslog_name)
#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))
return;
if (old_syslog_name)
- closelog();
+ {
+ closelog();
+ free(old_syslog_name);
+ }
if (new_syslog_name)
- openlog(new_syslog_name, LOG_CONS | LOG_NDELAY, LOG_DAEMON);
+ {
+ current_syslog_name = xmalloc(strlen(new_syslog_name) + 1);
+ strcpy(current_syslog_name, new_syslog_name);
+ openlog(current_syslog_name, LOG_CONS | LOG_NDELAY, LOG_DAEMON);
+ }
+ else
+ {
+ current_syslog_name = NULL;
+ }
#endif
}
More information about the Bird-users
mailing list