You are viewing a plain text version of this content. The canonical link for it is here.
Posted to apache-bugdb@apache.org by Matt Keith <ke...@keithcom.com> on 2001/05/08 01:47:35 UTC

general/7679: Null pointer SEGV possible in main/util.c

>Number:         7679
>Category:       general
>Synopsis:       Null pointer SEGV possible in main/util.c
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    apache
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   apache
>Arrival-Date:   Mon May 07 16:50:01 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     keith@keithcom.com
>Release:        1.3.19
>Organization:
apache
>Environment:
RedHat 7.1 - Linux 2.4.2-2 kernel on a 700 Mhz AMD Duron
>Description:
A SEGV core dump can happen if the system's fully qualified host name
can not be determined.  

In the ap_get_local_host function in main/util.c, it tries to get the 
host name, and if it fails it tries to get the IP from a possibly
null pointer.  The pointer needs to be tested before it is used.

>How-To-Repeat:
Run on a system without a fully qualified domain name in a dns or hosts file.
>Fix:
Here is the code snippet:

        str[sizeof(str) - 1] = '\0';
        if ((!(p = gethostbyname(str)))
            || (!(server_hostname = find_fqdn(a, p)))) {
            /* Recovery - return the default servername by IP: */
            if (p->h_addr_list[0]) {
                ap_snprintf(str, sizeof(str), "%pA", p->h_addr_list[0]);
                server_hostname = ap_pstrdup(a, str);
                /* We will drop through to report the IP-named server */
            }
        }

To check for a valid pointer, it should be:

        str[sizeof(str) - 1] = '\0';
        if ((!(p = gethostbyname(str)))
            || (!(server_hostname = find_fqdn(a, p)))) {
            /* Recovery - return the default servername by IP: */
>Release-Note:
>Audit-Trail:
>Unformatted:
 [In order for any reply to be added to the PR database, you need]
 [to include <ap...@Apache.Org> in the Cc line and make sure the]
 [subject line starts with the report component and number, with ]
 [or without any 'Re:' prefixes (such as "general/1098:" or      ]
 ["Re: general/1098:").  If the subject doesn't match this       ]
 [pattern, your message will be misfiled and ignored.  The       ]
 ["apbugs" address is not added to the Cc line of messages from  ]
 [the database automatically because of the potential for mail   ]
 [loops.  If you do not include this Cc, your reply may be ig-   ]
 [nored unless you are responding to an explicit request from a  ]
 [developer.  Reply only with text; DO NOT SEND ATTACHMENTS!     ]
 
 
 >>>         if (p && p->h_addr_list[0]) {
                 ap_snprintf(str, sizeof(str), "%pA", p->h_addr_list[0]);
                 server_hostname = ap_pstrdup(a, str);
                 /* We will drop through to report the IP-named server */
             }
         }