Subject: pkg/13751: apache6-1.3.19 can't get server hostname automatically
To: None <gnats-bugs@gnats.netbsd.org>
From: None <nagae@tk.airnet.ne.jp>
List: netbsd-bugs
Date: 08/20/2001 01:38:50
>Number:         13751
>Category:       pkg
>Synopsis:       apache6-1.3.19 can't get server hostname automatically
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sun Aug 19 09:35:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Nagae Hidetake
>Release:        Aug 3 2001
>Organization:
>Environment:
System: NetBSD dixie.nag.notwork.org 1.5W NetBSD 1.5W (X20) #1: Sat Jun 23 09:14:38 JST 2001 nagae@johnny.nag.notwork.org:/usr/src/sys/arch/i386/compile/X20 i386
Architecture: i386
Machine: i386
>Description:
If ServerName is not defined in httpd.conf, apache gets one via the function
ap_get_local_host().  This function is modified to call getaddrinfo()
by IPv6 patch apache-1.3.19-v6-20010301a.diff.gz.  But the patch doesn't
process results correctly, so the following problems occur:

1. If getaddrinfo() successes, ap_get_local_host() returns NULL pointer.
   In this case, for example, server hostname in error pages will be
   null string.
2. If getaddrinfo() fails, ap_get_local_host() refers NULL pointer,
   and dumps core immediately.
>How-To-Repeat:
Delete (or comment out) ServerName definition from httpd.conf,
and start apache.
>Fix:
Apply the following patch after `make patch', then `make'.

diff -rc apache_1.3.19.orig/src/main/util.c apache_1.3.19/src/main/util.c
*** apache_1.3.19.orig/src/main/util.c	Sun Aug 19 23:11:12 2001
--- apache_1.3.19/src/main/util.c	Sun Aug 19 23:25:18 2001
***************
*** 2087,2103 ****
  	hints.ai_flags = AI_CANONNAME;
  	res = NULL;
  	error = getaddrinfo(str, NULL, &hints, &res);
! 	if (error == 0)
  	{
  	    /* Since we found a fdqn, return it with no logged message. */
! 	    if (res)
! 		freeaddrinfo(res);
  	    return server_hostname;
  	}
  	else
  	{
              /* Recovery - return the default servername by IP: */
! 	    server_hostname = ap_pstrdup(a, res->ai_canonname);
  	    /* We will drop through to report the IP-named server */
  	}
  
--- 2087,2103 ----
  	hints.ai_flags = AI_CANONNAME;
  	res = NULL;
  	error = getaddrinfo(str, NULL, &hints, &res);
! 	if (error == 0 && res)
  	{
  	    /* Since we found a fdqn, return it with no logged message. */
! 	    server_hostname = ap_pstrdup(a, res->ai_canonname);
! 	    freeaddrinfo(res);
  	    return server_hostname;
  	}
  	else
  	{
              /* Recovery - return the default servername by IP: */
! 	    server_hostname = ap_pstrdup(a, str);
  	    /* We will drop through to report the IP-named server */
  	}
  

>Release-Note:
>Audit-Trail:
>Unformatted: