httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "William A. Rowe, Jr." <ad...@rowe-clan.net>
Subject Re: [PATCH](apache 1.3) ap_get_local_host() dereferencing NULLpointers...
Date Thu, 29 Mar 2001 16:35:38 GMT
Looks good to me.

+1

----- Original Message -----
From: "Brad Nicholes" <BNICHOLES@novell.com>
To: <new-httpd@apache.org>
Sent: Wednesday, March 28, 2001 2:28 PM
Subject: [PATCH](apache 1.3) ap_get_local_host() dereferencing NULLpointers...


   The api ap_get_local_host() along with find_fqdn() do not check to make sure that (struct
hostent)p->h_aliases is a valid pointer
before dereferencing it and using it in a string comparison.  If this pointer is NULL, which
happens on NetWare when there are no
aliases in the HOSTS file for the server, Apache faults while trying to reference invalid
memory.  The following code changes should
fix this problem on all platforms.  Please let me know if there are any problems with this
code change before I check it in.

thanks,
Brad Nicholes

--- d:\tempapache\apache-1.3\src\main\util.c Thu Feb 01 10:06:37 2001
+++ d:\projects\1.3.x\src\main\util.c Wed Mar 28 20:09:09 2001
@@ -2013,12 +2013,14 @@
     int x;

     if (!strchr(p->h_name, '.')) {
- for (x = 0; p->h_aliases[x]; ++x) {
-     if (strchr(p->h_aliases[x], '.') &&
- (!strncasecmp(p->h_aliases[x], p->h_name, strlen(p->h_name))))
- return ap_pstrdup(a, p->h_aliases[x]);
- }
- return NULL;
+        if (p->h_aliases) {
+            for (x = 0; p->h_aliases[x]; ++x) {
+                if (p->h_aliases[x] && strchr(p->h_aliases[x], '.') &&
+                    (!strncasecmp(p->h_aliases[x], p->h_name, strlen(p->h_name))))
+                    return ap_pstrdup(a, p->h_aliases[x]);
+            }
+        }
+        return NULL;
     }
     return ap_pstrdup(a, (void *) p->h_name);
 }
@@ -2048,7 +2050,7 @@
         if ((!(p = gethostbyname(str)))
             || (!(server_hostname = find_fqdn(a, p)))) {
             /* Recovery - return the default servername by IP: */
-            if (p->h_addr_list[0]) {
+            if (p->h_addr_list && 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 */





Mime
View raw message