httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cove...@apache.org
Subject svn commit: r1053309 - in /httpd/httpd/trunk: CHANGES server/vhost.c
Date Tue, 28 Dec 2010 11:21:56 GMT
Author: covener
Date: Tue Dec 28 11:21:56 2010
New Revision: 1053309

URL: http://svn.apache.org/viewvc?rev=1053309&view=rev
Log:
prefer exact port matches in ip-based VH lookup over wildcards.


Modified:
    httpd/httpd/trunk/CHANGES
    httpd/httpd/trunk/server/vhost.c

Modified: httpd/httpd/trunk/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=1053309&r1=1053308&r2=1053309&view=diff
==============================================================================
--- httpd/httpd/trunk/CHANGES [utf-8] (original)
+++ httpd/httpd/trunk/CHANGES [utf-8] Tue Dec 28 11:21:56 2010
@@ -2,6 +2,10 @@
 
 Changes with Apache 2.3.11
 
+  *) core: When selecting an IP-based virtual host, favor an exact match for
+     the port over a wildcard (or omitted) port instead of favoring the one
+     that came first in the configuration file. [Eric Covener]
+
   *) core: Overlapping virtual host address/port combinations  now implicitly 
      enable name-based virtual hosting for that address.  The NameVirtualHost
      directive has no effect, and _default_ is interpreted the same as "*". 

Modified: httpd/httpd/trunk/server/vhost.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/vhost.c?rev=1053309&r1=1053308&r2=1053309&view=diff
==============================================================================
--- httpd/httpd/trunk/server/vhost.c (original)
+++ httpd/httpd/trunk/server/vhost.c Tue Dec 28 11:21:56 2010
@@ -376,7 +376,8 @@ static name_chain *new_name_chain(apr_po
 static APR_INLINE ipaddr_chain *find_ipaddr(apr_sockaddr_t *sa)
 {
     unsigned bucket;
-    ipaddr_chain *trav;
+    ipaddr_chain *trav = NULL;
+    ipaddr_chain *wild_match = NULL;
 
     /* scan the hash table for an exact match first */
     bucket = hash_addr(sa);
@@ -384,28 +385,39 @@ static APR_INLINE ipaddr_chain *find_ipa
         server_addr_rec *sar = trav->sar;
         apr_sockaddr_t *cur = sar->host_addr;
 
-        if (cur->port == 0 || sa->port == 0 || cur->port == sa->port) {
+        if (cur->port == sa->port) {
             if (apr_sockaddr_equal(cur, sa)) {
                 return trav;
             }
         }
+        if (wild_match == NULL && (cur->port == 0 || sa->port == 0)) {
+            if (apr_sockaddr_equal(cur, sa)) {
+                /* don't break, continue looking for an exact match */
+                wild_match = trav; 
+            }
+        }
     }
-    return NULL;
+    return wild_match;
 }
 
 static ipaddr_chain *find_default_server(apr_port_t port)
 {
     server_addr_rec *sar;
-    ipaddr_chain *trav;
+    ipaddr_chain *trav = NULL;
+    ipaddr_chain *wild_match = NULL;
 
     for (trav = default_list; trav; trav = trav->next) {
         sar = trav->sar;
-        if (sar->host_port == 0 || sar->host_port == port) {
+        if (sar->host_port == port) {
             /* match! */
             return trav;
         }
+        if (wild_match == NULL && sar->host_port == 0) {
+            /* don't break, continue looking for an exact match */
+            wild_match = trav;
+        } 
     }
-    return NULL;
+    return wild_match;
 }
 
 static void dump_a_vhost(apr_file_t *f, ipaddr_chain *ic)



Mime
View raw message