nginx-0.3.31-RELEASE import

    *) 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; the bug had 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.
diff --git a/src/core/nginx.h b/src/core/nginx.h
index d0ff27f..e8f6084 100644
--- a/src/core/nginx.h
+++ b/src/core/nginx.h
@@ -8,7 +8,7 @@
 #define _NGINX_H_INCLUDED_
 
 
-#define NGINX_VER          "nginx/0.3.30"
+#define NGINX_VER          "nginx/0.3.31"
 
 #define NGINX_VAR          "NGINX"
 #define NGX_OLDPID_EXT     ".oldbin"
diff --git a/src/core/ngx_hash.c b/src/core/ngx_hash.c
index 1f677c9..2876318 100644
--- a/src/core/ngx_hash.c
+++ b/src/core/ngx_hash.c
@@ -741,10 +741,10 @@
     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 @@
          *      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 @@
         }
 
         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 @@
         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;