[nginx] svn commit: r4724 - in branches/stable-1.2: . src/core src/os/unix

mdounin at mdounin.ru mdounin at mdounin.ru
Mon Jul 2 16:23:15 UTC 2012


Author: mdounin
Date: 2012-07-02 16:23:14 +0000 (Mon, 02 Jul 2012)
New Revision: 4724
URL: http://trac.nginx.org/nginx/changeset/4724/nginx

Log:
Merge of r4654, r4672, r4684, r4685, r4692: resolver changes.

*) Resolver: fixed format specification.
   Patch by Yichun Zhang (agentzh).

*) Support for IPv6 literals and an optional port in resolver.

*) Fixed crash in ngx_resolver_cleanup_tree().

   If sending a DNS request fails with an error (e.g., when mistakenly
   trying to send it to a local IP broadcast), such a request is not
   deleted if there are clients waiting on it.  However, it was still
   erroneously removed from the queue.  Later ngx_resolver_cleanup_tree()
   attempted to remove it from the queue again that resulted in a NULL
   pointer dereference.

*) When "resolver" is configured with a domain name, only the first
   resolved address was used.  Now all addresses will be used.

*) Fixed segfault with poll and resolver used.

   Poll event method needs ngx_cycle->files to work, and use of
   ngx_exit_cycle without files set caused null pointer dereference in  
   resolver's cleanup on udp socket close.


Modified:
   branches/stable-1.2/
   branches/stable-1.2/src/core/ngx_resolver.c
   branches/stable-1.2/src/os/unix/ngx_process_cycle.c

Index: branches/stable-1.2
===================================================================
--- branches/stable-1.2	2012-07-02 16:16:27 UTC (rev 4723)
+++ branches/stable-1.2	2012-07-02 16:23:14 UTC (rev 4724)

Property changes on: branches/stable-1.2
___________________________________________________________________
Modified: svn:mergeinfo
## -1 +1 ##
-/trunk:4611-4632,4636-4653,4671,4674-4676
+/trunk:4611-4632,4636-4654,4671-4672,4674-4676,4684-4685,4692
\ No newline at end of property
Modified: branches/stable-1.2/src/core/ngx_resolver.c
===================================================================
--- branches/stable-1.2/src/core/ngx_resolver.c	2012-07-02 16:16:27 UTC (rev 4723)
+++ branches/stable-1.2/src/core/ngx_resolver.c	2012-07-02 16:23:14 UTC (rev 4724)
@@ -96,7 +96,7 @@
 {
     ngx_str_t              s;
     ngx_url_t              u;
-    ngx_uint_t             i;
+    ngx_uint_t             i, j;
     ngx_resolver_t        *r;
     ngx_pool_cleanup_t    *cln;
     ngx_udp_connection_t  *uc;
@@ -171,29 +171,31 @@
 
         ngx_memzero(&u, sizeof(ngx_url_t));
 
-        u.host = names[i];
-        u.port = 53;
+        u.url = names[i];
+        u.default_port = 53;
 
-        if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) {
+        if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
             if (u.err) {
                 ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
                                    "%s in resolver \"%V\"",
-                                   u.err, &u.host);
+                                   u.err, &u.url);
             }
 
             return NULL;
         }
 
-        uc = ngx_array_push(&r->udp_connections);
+        uc = ngx_array_push_n(&r->udp_connections, u.naddrs);
         if (uc == NULL) {
             return NULL;
         }
 
-        ngx_memzero(uc, sizeof(ngx_udp_connection_t));
+        ngx_memzero(uc, u.naddrs * sizeof(ngx_udp_connection_t));
 
-        uc->sockaddr = u.addrs->sockaddr;
-        uc->socklen = u.addrs->socklen;
-        uc->server = u.addrs->name;
+        for (j = 0; j < u.naddrs; j++) {
+            uc[j].sockaddr = u.addrs[j].sockaddr;
+            uc[j].socklen = u.addrs[j].socklen;
+            uc[j].server = u.addrs[j].name;
+        }
     }
 
     return r;
@@ -977,12 +979,11 @@
 
         if (rn->waiting) {
 
-            if (ngx_resolver_send_query(r, rn) == NGX_OK) {
+            (void) ngx_resolver_send_query(r, rn);
 
-                rn->expire = now + r->resend_timeout;
+            rn->expire = now + r->resend_timeout;
 
-                ngx_queue_insert_head(queue, &rn->queue);
-            }
+            ngx_queue_insert_head(queue, q);
 
             continue;
         }
@@ -1040,7 +1041,7 @@
     nan = (query->nan_hi << 8) + query->nan_lo;
 
     ngx_log_debug6(NGX_LOG_DEBUG_CORE, r->log, 0,
-                   "resolver DNS response %ui fl:%04Xui %ui/%ui/%ui/%ui",
+                   "resolver DNS response %ui fl:%04Xui %ui/%ui/%ud/%ud",
                    ident, flags, nqs, nan,
                    (query->nns_hi << 8) + query->nns_lo,
                    (query->nar_hi << 8) + query->nar_lo);
@@ -2189,7 +2190,7 @@
     ngx_socket_t       s;
     ngx_connection_t  *c;
 
-    s = ngx_socket(AF_INET, SOCK_DGRAM, 0);
+    s = ngx_socket(uc->sockaddr->sa_family, SOCK_DGRAM, 0);
 
     ngx_log_debug1(NGX_LOG_DEBUG_EVENT, &uc->log, 0, "UDP socket %d", s);
 

Modified: branches/stable-1.2/src/os/unix/ngx_process_cycle.c
===================================================================
--- branches/stable-1.2/src/os/unix/ngx_process_cycle.c	2012-07-02 16:16:27 UTC (rev 4723)
+++ branches/stable-1.2/src/os/unix/ngx_process_cycle.c	2012-07-02 16:23:14 UTC (rev 4724)
@@ -711,6 +711,8 @@
     ngx_exit_log.file = &ngx_exit_log_file;
 
     ngx_exit_cycle.log = &ngx_exit_log;
+    ngx_exit_cycle.files = ngx_cycle->files;
+    ngx_exit_cycle.files_n = ngx_cycle->files_n;
     ngx_cycle = &ngx_exit_cycle;
 
     ngx_destroy_pool(cycle->pool);
@@ -1054,6 +1056,8 @@
     ngx_exit_log.file = &ngx_exit_log_file;
 
     ngx_exit_cycle.log = &ngx_exit_log;
+    ngx_exit_cycle.files = ngx_cycle->files;
+    ngx_exit_cycle.files_n = ngx_cycle->files_n;
     ngx_cycle = &ngx_exit_cycle;
 
     ngx_destroy_pool(cycle->pool);



More information about the nginx-devel mailing list