NetBSD Problem Report #47921

From Wolfgang.Stukenbrock@nagler-company.com  Wed Jun 12 13:49:43 2013
Return-Path: <Wolfgang.Stukenbrock@nagler-company.com>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	(using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id E4D5B7069C
	for <gnats-bugs@gnats.NetBSD.org>; Wed, 12 Jun 2013 13:49:43 +0000 (UTC)
Message-Id: <20130612134933.D61B9123B93@test-s0.nagler-company.com>
Date: Wed, 12 Jun 2013 15:49:33 +0200 (CEST)
From: Wolfgang.Stukenbrock@nagler-company.com
Reply-To: Wolfgang.Stukenbrock@nagler-company.com
To: gnats-bugs@gnats.NetBSD.org
Subject: syslogd losses config information while stripping domainname
X-Send-Pr-Version: 3.95

>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:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.