Subject: bin/30879: syslogd(8) doesn't parse `@' hostname specification correctly
To: None <gnats-admin@netbsd.org, netbsd-bugs@netbsd.org>
From: None <j+nbsd@2005.salmi.ch>
List: netbsd-bugs
Date: 07/30/2005 17:17:00
>Number:         30879
>Category:       bin
>Synopsis:       syslogd(8) doesn't parse `@' hostname specification correctly
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Jul 30 17:17:00 +0000 2005
>Originator:     Jukka Salmi
>Release:        NetBSD 3.99.7
>Environment:
System: NetBSD moray.salmi.ch 3.99.7 NetBSD 3.99.7 (MORAY) #0: Thu Jul 28 10:32:53 CEST 2005 build@moray.salmi.ch:/build/nbsd/i386/sys/arch/i386/compile/MORAY i386
Architecture: i386
Machine: i386
>Description:

Syslogd doesn't parse hostname specification lines from syslog.conf
correctly if they contain the `@' character (meaning `local hostname')
together with (an)other hostname(s). In this case only the local
hostname is taken into account.

>How-To-Repeat:

Add a line like the following to /etc/syslog.conf:

-@,host1,host2
*.* /var/log/test

start syslogd:

$ syslogd -d
[...]
cfline("*.* /var/log/test", f, "*", "-moray")
[...]

and notice host1 and host2 are not passed to cfline (last argument).

>Fix:

Patch is attached and available from
http://salmi.ch/~jukka/patches/nbsd/HEAD/usr.sbin/syslogd/localhost.patch

Index: syslogd.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/syslogd/syslogd.c,v
retrieving revision 1.76
diff -u -p -r1.76 syslogd.c
--- syslogd.c	2 Jun 2005 09:42:57 -0000	1.76
+++ syslogd.c	30 Jul 2005 17:02:58 -0000
@@ -1703,9 +1703,15 @@ init(struct kevent *ev)
 				strcpy(host, "*");
 				continue;
 			}
-			if (*p == '@')
-				p = LocalHostName;
 			for (i = 1; i < MAXHOSTNAMELEN - 1; i++) {
+				if (*p == '@') {
+					strncpy(&host[i], LocalHostName,
+					    MAXHOSTNAMELEN-1-i);
+					host[MAXHOSTNAMELEN-1] = '\0';
+					i = strlen(host)-1;
+					p++;
+					continue;
+				}
 				if (!isalnum((unsigned char)*p) &&
 				    *p != '.' && *p != '-' && *p != ',')
 					break;