diff src/core/ngx_hash.c @ 168:3314be145cb9 NGINX_0_3_31

nginx 0.3.31 *) Change: now nginx passes the malformed proxied backend responses. *) Feature: the "listen" directives support the address in the "*:port" form. *) Feature: the EVFILER_TIMER support in MacOSX 10.4. *) Workaround: for MacOSX 64-bit kernel kqueue millisecond timeout bug. Thanks to Andrei Nigmatulin. *) Bugfix: if there were several "listen" directives listening one various addresses inside one server, then server names like "*.domain.tld" worked for first address only; bug appeared in 0.3.18. *) Bugfix: if the HTTPS protocol was used in the "proxy_pass" directive and the request body was in temporarily file then the request was not transferred. *) Bugfix: perl 5.8.8 compatibility.
author Igor Sysoev <http://sysoev.ru>
date Fri, 10 Mar 2006 00:00:00 +0300
parents 36af50a5582d
children 4cd3e70c4d60
line wrap: on
line diff
--- a/src/core/ngx_hash.c
+++ b/src/core/ngx_hash.c
@@ -741,10 +741,10 @@ ngx_hash_add_key(ngx_hash_keys_arrays_t 
     ngx_uint_t flags)
 {
     size_t           len;
+    u_char          *reverse;
     ngx_str_t       *name;
     ngx_uint_t       i, k, n, skip;
     ngx_hash_key_t  *hk;
-    u_char           buf[2048];
 
     if (!(flags & NGX_HASH_WILDCARD_KEY)) {
 
@@ -863,14 +863,19 @@ ngx_hash_add_key(ngx_hash_keys_arrays_t 
          *      and ".example.com" to "com.example\0"
          */
 
+        reverse = ngx_palloc(ha->temp_pool, key->len);
+        if (reverse == NULL) {
+            return NGX_ERROR;
+        }
+
         len = 0;
         n = 0;
 
         for (i = key->len - 1; i; i--) {
             if (key->data[i] == '.') {
-                ngx_memcpy(&buf[n], &key->data[i + 1], len);
+                ngx_memcpy(&reverse[n], &key->data[i + 1], len);
                 n += len;
-                buf[n++] = '.';
+                reverse[n++] = '.';
                 len = 0;
                 continue;
             }
@@ -879,11 +884,22 @@ ngx_hash_add_key(ngx_hash_keys_arrays_t 
         }
 
         if (len) {
-            ngx_memcpy(&buf[n], &key->data[1], len);
+            ngx_memcpy(&reverse[n], &key->data[1], len);
             n += len;
         }
 
-        buf[n] = '\0';
+        reverse[n] = '\0';
+
+
+        hk = ngx_array_push(&ha->dns_wildcards);
+        if (hk == NULL) {
+            return NGX_ERROR;
+        }
+
+        hk->key.len = key->len - 1;
+        hk->key.data = reverse;
+        hk->key_hash = 0;
+        hk->value = value;
 
 
         /* check conflicts in wildcard hash */
@@ -922,20 +938,8 @@ ngx_hash_add_key(ngx_hash_keys_arrays_t 
         if (name->data == NULL) {
             return NGX_ERROR;
         }
+
         ngx_memcpy(name->data, key->data + skip, name->len);
-
-
-        ngx_memcpy(key->data, buf, key->len);
-        key->len--;
-
-        hk = ngx_array_push(&ha->dns_wildcards);
-        if (hk == NULL) {
-            return NGX_ERROR;
-        }
-
-        hk->key = *key;
-        hk->key_hash = 0;
-        hk->value = value;
     }
 
     return NGX_OK;