Subject: bin/1066: syslogd misuses h_errlist and core dumps
To: None <gnats-admin@sun-lamp.cs.berkeley.edu>
From: John Hawkinson <jhawk@MIT.EDU>
List: netbsd-bugs
Date: 05/19/1995 01:35:03
>Number:         1066
>Category:       bin
>Synopsis:       syslogd misuses h_errlist and core dumps
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people (Utility Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri May 19 01:35:02 1995
>Originator:     John Hawkinson
>Organization:
MIT SIPB
>Release:        -current Fri May 19 04:32:33 EDT 1995
>Environment:
	
System: NetBSD lola-granola 1.0A NetBSD 1.0A (LOLA) #14: Thu May 18 15:17:31 EDT 1995 mycroft@limekiller:/afs/sipb.mit.edu/system/i386_nbsd1/usr/src/sys/arch/i386/compile/LOLA i386


>Description:

	Under some cases, when making use of "hostname forwarding", syslogd
	seems to core dump. This tends to be noticed when the newsyslog
	cron job runs and mail is sent.

	syslogd.c also lacks a $NetBSD$ tag.

	As an aside (perhaps more suited for current-users than a PR),
	why is _PATH_LOGPID set to
		/var/run/syslog.pid
	rather than the expected
		/var/run/syslogd.pid
	? Purely for historical reasons?

>How-To-Repeat:

syslog.conf contains the following line:
	local1.*                                        @portnoy

This seems to lead to occasional problems; I can only speculate as to
why gethostbyname() was returning null with any regularity, but that
seems irrelevant...

[lola-granola!jhawk] /> gdb syslogd syslogd.core
GDB is free software and you are welcome to distribute copies of it
 under certain conditions; type "show copying" to see the conditions.
There is absolutely no warranty for GDB; type "show warranty" for details.
GDB 4.11 (i386-netbsd), Copyright 1993 Free Software Foundation, Inc...
Core was generated by `syslogd'.
Program terminated with signal 11, Segmentation fault.
Reading symbols from /usr/libexec/ld.so...done.
Reading symbols from /usr/lib/libc.so.12.3...done.
#0  0x10053e4a in vfprintf ()
(gdb) where
#0  0x10053e4a in vfprintf ()
#1  0x100456d0 in sprintf ()
#2  0x2cf2 in logerror (type=0x302072 "") at syslogd.c:819
#3  0x3413 in cfline (line=0xf7bfc8bc "\t\t\t\t\t@portnoy", f=0xe800)
    at syslogd.c:1049
#4  0x3018 in init () at syslogd.c:914
#5  0x1d89 in main (argc=268920464, argv=0x5) at syslogd.c:301
(gdb)
(gdb) list 1049
1044                    hp = gethostbyname(p);
1045                    if (hp == NULL) {
1046                            extern int h_errno, h_nerr;
1047                            extern char **h_errlist;
1048
1049                            logerror((u_int)h_errno < h_nerr ?
1050                                h_errlist[h_errno] : "Unknown error");
1051                            break;
1052                    }
1053                    bzero((char *) &f->f_un.f_forw.f_addr,

>Fix:

	The source of the problem is that syslogd misdeclares h_errlist;
this could be solved by either nuking h_errlist from orbit and using
hstrerror(), or by prototyping h_errlist in netdb.h. I choose the former
alternative. If h_errno is included in netdb.h per PR lib/1065, declaring
it is unnecessary, but I assume that's not the case in my patch, so far.

*** syslogd.c	Fri May 19 04:27:40 1995
--- /usr/src/usr.sbin/syslogd/syslogd.c	Fri May 19 04:28:29 1995
***************
*** 39,45 ****
  
  #ifndef lint
  /*static char sccsid[] = "from: @(#)syslogd.c	5.45 (Berkeley) 3/2/91";*/
! static char rcsid[] = "$Id: syslogd.c,v 1.3 1995/05/14 04:18:45 cgd Exp $";
  #endif /* not lint */
  
  /*
--- 39,45 ----
  
  #ifndef lint
  /*static char sccsid[] = "from: @(#)syslogd.c	5.45 (Berkeley) 3/2/91";*/
! static char rcsid[] = "$NetBSD: syslogd.c,v 1.3 1995/05/14 04:18:45 cgd Exp $";
  #endif /* not lint */
  
  /*
***************
*** 1043,1053 ****
  		(void) strcpy(f->f_un.f_forw.f_hname, ++p);
  		hp = gethostbyname(p);
  		if (hp == NULL) {
! 			extern int h_errno, h_nerr;
! 			extern char **h_errlist;
  
! 			logerror((u_int)h_errno < h_nerr ?
! 			    h_errlist[h_errno] : "Unknown error");
  			break;
  		}
  		bzero((char *) &f->f_un.f_forw.f_addr,
--- 1043,1051 ----
  		(void) strcpy(f->f_un.f_forw.f_hname, ++p);
  		hp = gethostbyname(p);
  		if (hp == NULL) {
! 			extern int h_errno;
  
! 			logerror(hstrerror(h_errno));
  			break;
  		}
  		bzero((char *) &f->f_un.f_forw.f_addr,
>Audit-Trail:
>Unformatted: