NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/47921: syslogd losses config information while stripping domainname



>Number:         47921
>Category:       bin
>Synopsis:       syslogd losses config information while stripping domainname
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jun 12 13:50:00 +0000 2013
>Originator:     Dr. Wolfgang Stukenbrock
>Release:        NetBSD 6.1
>Organization:
Dr. Nagler & Company GmbH
>Environment:
        
        
System: NetBSD test-s0 5.1.2 NetBSD 5.1.2 (NSW-WS) #3: Fri Dec 21 15:15:43 CET 
2012 wgstuken@test-s0:/usr/src/sys/arch/amd64/compile/NSW-WS amd64
Architecture: x86_64
Machine: amd64
>Description:
        The configuration file syslog.conf allows list of hostnames to select 
special
        placemant of the syslog - see syslog.conf(4). e.g. +host1,host2,host3
        The problem is, that the trim-routine just replaces the first '.' with 
'\0'.
        It should search for ',' and shrink the buffer to kill the domain parts.

        This problem is in 5.1.2 too. There the function trim_localdomain() 
also only kills the last
        domain part so that "+host1.test.com,host2.test.com" would be 
"+host1.test.com,host2" if
        the extracted local domainname was "test.com". The fix for this routine 
would be more
        complicate, because some assumption of this routine are no longer valid 
...

        By the way, the local variable "char host[MAXHOSTNAMELEN];" in function 
"read_config_file()"
        should be more dynamic. It doesn't hold only one host name, it may hold 
a list of hostnames.
        The current implentation limits the length of each list to 255 char and 
that is not very much ...
>How-To-Repeat:
        setup a config line like "+host1.test.com,host2.test.com" and use 
default or rfc-mode.
        Only "+host1" will remain and the messages from "host2" will not go 
into the special block.
>Fix:
        The following patch to /usr/src/usr.sbin/syslogd/syslogd.c will solve 
the problem:

--- syslogd.c   2013/06/12 12:45:35     1.1
+++ syslogd.c   2013/06/12 13:24:30
@@ -2640,7 +2640,7 @@
 trim_anydomain(char *host)
 {
        bool onlydigits = true;
-       int i;
+       int i, j;
 
        if (!BSDOutputFormat)
                return;
@@ -2648,11 +2648,18 @@
        /* if non-digits found, then assume hostname and cut at first dot (this
         * case also covers IPv6 addresses which should not contain dots),
         * if only digits then assume IPv4 address and do not cut at all */
-       for (i = 0; host[i]; i++) {
-               if (host[i] == '.' && !onlydigits)
-                       host[i] = '\0';
+       for (i = j = 0; host[i];) {
+               if (host[i] == ',')
+                       onlydigits = true;
+               else if (host[i] == '.' && !onlydigits) {
+                       host[j] = '\0';
+                       for (i++; host[i] != '\0' && host[i] != ','; i++);
+                       continue;
+               }
                else if (!isdigit((unsigned char)host[i]) && host[i] != '.')
                        onlydigits = false;
+               if (j != i) host[j] = host[i];
+               i++; j++;
        }
 }
 

>Unformatted:
        
        


Home | Main Index | Thread Index | Old Index