Klaus Demo nginx / de6c14e
r3140, r3144, r3298, r3299, r3300, r3307, r3308 merge: resolver fixes: *) fix memory leak in resolver *) fix resolver cache rbtree comparison *) fix segfault in resolver: ngx_resolve_name_done() and ngx_resolve_addr_done() did not delete contexts from a resolver node waiting list. *) fix "PTR ." case in address resolver *) add quotes in an error message, *) fix resolving an empty name (".") *) use ngx_resolver_alloc() instead of ngx_resolver_calloc() since all fields are filled Igor Sysoev 12 years ago
2 changed file(s) with 24 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
463463
464464 ctx->next = rn->waiting;
465465 rn->waiting = ctx;
466 ctx->state = NGX_AGAIN;
466467
467468 return NGX_AGAIN;
468469 }
624625
625626 ctx->next = rn->waiting;
626627 rn->waiting = ctx;
628 ctx->state = NGX_AGAIN;
627629
628630 /* unlock addr mutex */
629631
11481150 goto failed;
11491151 }
11501152
1153 ngx_resolver_free(r, name.data);
1154
11511155 if (code == 0 && nan == 0) {
11521156 code = 3; /* NXDOMAIN */
11531157 }
13981402 failed:
13991403
14001404 /* unlock name mutex */
1405
1406 ngx_resolver_free(r, name.data);
14011407
14021408 return;
14031409 }
15941600 ngx_resolver_lookup_name(ngx_resolver_t *r, ngx_str_t *name, uint32_t hash)
15951601 {
15961602 ngx_int_t rc;
1597 size_t len;
15981603 ngx_rbtree_node_t *node, *sentinel;
15991604 ngx_resolver_node_t *rn;
16001605
16181623 do {
16191624 rn = (ngx_resolver_node_t *) node;
16201625
1621 len = (name->len > (size_t) rn->nlen) ? rn->nlen : name->len;
1622
1623 rc = ngx_strncmp(name->data, rn->name, len);
1626 rc = ngx_memn2cmp(name->data, rn->name, name->len, rn->nlen);
16241627
16251628 if (rc == 0) {
16261629 return rn;
16741677 ngx_resolver_rbtree_insert_value(ngx_rbtree_node_t *temp,
16751678 ngx_rbtree_node_t *node, ngx_rbtree_node_t *sentinel)
16761679 {
1677 size_t len;
16781680 ngx_rbtree_node_t **p;
16791681 ngx_resolver_node_t *rn, *rn_temp;
16801682
16931695 rn = (ngx_resolver_node_t *) node;
16941696 rn_temp = (ngx_resolver_node_t *) temp;
16951697
1696 len = (rn->nlen > rn_temp->nlen) ? rn_temp->nlen : rn->nlen;
1697
1698 p = (ngx_strncmp(rn->name, rn_temp->name, len) < 0)
1699 ? &temp->left : &temp->right;
1698 p = (ngx_memn2cmp(rn->name, rn_temp->name, rn->nlen, rn_temp->nlen)
1699 < 0) ? &temp->left : &temp->right;
17001700 }
17011701
17021702 if (*p == sentinel) {
17181718 ngx_resolver_create_name_query(ngx_resolver_node_t *rn, ngx_resolver_ctx_t *ctx)
17191719 {
17201720 u_char *p, *s;
1721 size_t len;
1721 size_t len, nlen;
17221722 ngx_uint_t ident;
17231723 ngx_resolver_qs_t *qs;
17241724 ngx_resolver_query_t *query;
17251725
1726 len = sizeof(ngx_resolver_query_t)
1727 + 1 + ctx->name.len + 1 + sizeof(ngx_resolver_qs_t);
1728
1729 p = ngx_resolver_calloc(ctx->resolver, len);
1726 nlen = ctx->name.len ? (1 + ctx->name.len + 1) : 1;
1727
1728 len = sizeof(ngx_resolver_query_t) + nlen + sizeof(ngx_resolver_qs_t);
1729
1730 p = ngx_resolver_alloc(ctx->resolver, len);
17301731 if (p == NULL) {
17311732 return NGX_ERROR;
17321733 }
17531754 query->nns_hi = 0; query->nns_lo = 0;
17541755 query->nar_hi = 0; query->nar_lo = 0;
17551756
1756 p += sizeof(ngx_resolver_query_t) + 1 + ctx->name.len + 1;
1757 p += sizeof(ngx_resolver_query_t) + nlen;
17571758
17581759 qs = (ngx_resolver_qs_t *) p;
17591760
18071808 + sizeof(".255.255.255.255.in-addr.arpa.") - 1
18081809 + sizeof(ngx_resolver_qs_t);
18091810
1810 p = ngx_resolver_calloc(ctx->resolver, len);
1811 p = ngx_resolver_alloc(ctx->resolver, len);
18111812 if (p == NULL) {
18121813 return NGX_ERROR;
18131814 }
18981899 done:
18991900
19001901 if (name == NULL) {
1902 return NGX_OK;
1903 }
1904
1905 if (len == -1) {
1906 name->len = 0;
1907 name->data = NULL;
19011908 return NGX_OK;
19021909 }
19031910
190190
191191 if (ctx->state) {
192192 ngx_log_error(NGX_LOG_ERR, c->log, 0,
193 "%V could not be resolved (%i: %s)",
193 "\"%V\" could not be resolved (%i: %s)",
194194 &ctx->name, ctx->state,
195195 ngx_resolver_strerror(ctx->state));
196196