]> git.kaiwu.me - nginx.git/commitdiff
If .domain.com, .sub.domain.com, and .domain-some.com were defined,
authorIgor Sysoev <igor@sysoev.ru>
Sat, 12 Sep 2009 09:28:37 +0000 (09:28 +0000)
committerIgor Sysoev <igor@sysoev.ru>
Sat, 12 Sep 2009 09:28:37 +0000 (09:28 +0000)
then .sub.domain.com was matched by .domain.com: wildcard names hash
was built incorrectly due to sorting order issue of "." vs "-".
They were sorted as
    com.domain  com.domain-some  com.domain.sub
while they should be sorted as
    com.domain  com.domain.sub   com.domain-some
for correct hash building

src/core/ngx_string.c
src/core/ngx_string.h
src/http/modules/ngx_http_map_module.c
src/http/modules/ngx_http_referer_module.c
src/http/ngx_http.c

index c0bcc1d123f459dca21da0631594dd5afe62be65..3456baa5c5415550143ef7f8ca7751d5a98ad086 100644 (file)
@@ -819,6 +819,37 @@ ngx_memn2cmp(u_char *s1, u_char *s2, size_t n1, size_t n2)
 }
 
 
+ngx_int_t
+ngx_dns_strcmp(u_char *s1, u_char *s2)
+{
+    ngx_uint_t  c1, c2;
+
+    for ( ;; ) {
+        c1 = (ngx_uint_t) *s1++;
+        c2 = (ngx_uint_t) *s2++;
+
+        c1 = (c1 >= 'A' && c1 <= 'Z') ? (c1 | 0x20) : c1;
+        c2 = (c2 >= 'A' && c2 <= 'Z') ? (c2 | 0x20) : c2;
+
+        if (c1 == c2) {
+
+            if (c1) {
+                continue;
+            }
+
+            return 0;
+        }
+
+        /* in ASCII '.' > '-', but we need '.' to be the lowest character */
+
+        c1 = (c1 == '.') ? ' ' : c1;
+        c2 = (c2 == '.') ? ' ' : c2;
+
+        return c1 - c2;
+    }
+}
+
+
 ngx_int_t
 ngx_atoi(u_char *line, size_t n)
 {
index 81e1ea169191be3a054c76cc14da81a3961e2aef..0525b0e248fffee0f9f1cd47bd1e95bf0f0bc286 100644 (file)
@@ -158,6 +158,7 @@ u_char *ngx_strlcasestrn(u_char *s1, u_char *last, u_char *s2, size_t n);
 ngx_int_t ngx_rstrncmp(u_char *s1, u_char *s2, size_t n);
 ngx_int_t ngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n);
 ngx_int_t ngx_memn2cmp(u_char *s1, u_char *s2, size_t n1, size_t n2);
+ngx_int_t ngx_dns_strcmp(u_char *s1, u_char *s2);
 
 ngx_int_t ngx_atoi(u_char *line, size_t n);
 ssize_t ngx_atosz(u_char *line, size_t n);
index 1f7786c3ce952fdbc059c247d18d925b92c5b548..abdae0d3be9e78bac0656e9d4e82ba6b780e710c 100644 (file)
@@ -337,7 +337,7 @@ ngx_http_map_cmp_dns_wildcards(const void *one, const void *two)
     first = (ngx_hash_key_t *) one;
     second = (ngx_hash_key_t *) two;
 
-    return ngx_strcmp(first->key.data, second->key.data);
+    return ngx_dns_strcmp(first->key.data, second->key.data);
 }
 
 
index 658f4a19c2c6529a43df238a898d633b4aafae9d..608623f70f0aa717c6171b818c69654e901201ff 100644 (file)
@@ -562,5 +562,5 @@ ngx_http_cmp_referer_wildcards(const void *one, const void *two)
     first = (ngx_hash_key_t *) one;
     second = (ngx_hash_key_t *) two;
 
-    return ngx_strcmp(first->key.data, second->key.data);
+    return ngx_dns_strcmp(first->key.data, second->key.data);
 }
index b0915157cd46c947ae37c18a67a8239542f33d20..f5cb430faf9766318e12953b0b1fb6d5e4b0951b 100644 (file)
@@ -1601,7 +1601,7 @@ ngx_http_cmp_dns_wildcards(const void *one, const void *two)
     first = (ngx_hash_key_t *) one;
     second = (ngx_hash_key_t *) two;
 
-    return ngx_strcmp(first->key.data, second->key.data);
+    return ngx_dns_strcmp(first->key.data, second->key.data);
 }