Resolver: simplified ngx_resolver_copy().

Instead of checking on each label if we need to place a dot or not,
now it always adds a dot after a label, and reduces the resulting
length afterwards.
This commit is contained in:
Maxim Dounin 2021-05-25 15:17:45 +03:00
parent f1dd1d50e0
commit f85d701694

View File

@ -3939,11 +3939,11 @@ ngx_resolver_copy(ngx_resolver_t *r, ngx_str_t *name, u_char *buf, u_char *src,
{ {
char *err; char *err;
u_char *p, *dst; u_char *p, *dst;
ssize_t len; size_t len;
ngx_uint_t i, n; ngx_uint_t i, n;
p = src; p = src;
len = -1; len = 0;
/* /*
* compression pointers allow to create endless loop, so we set limit; * compression pointers allow to create endless loop, so we set limit;
@ -3996,7 +3996,7 @@ done:
return NGX_OK; return NGX_OK;
} }
if (len == -1) { if (len == 0) {
ngx_str_null(name); ngx_str_null(name);
return NGX_OK; return NGX_OK;
} }
@ -4012,7 +4012,7 @@ done:
n = *src++; n = *src++;
if (n == 0) { if (n == 0) {
name->len = dst - name->data; name->len = dst - name->data - 1;
return NGX_OK; return NGX_OK;
} }
@ -4021,13 +4021,10 @@ done:
src = &buf[n]; src = &buf[n];
} else { } else {
if (dst != name->data) {
*dst++ = '.';
}
ngx_strlow(dst, src, n); ngx_strlow(dst, src, n);
dst += n; dst += n;
src += n; src += n;
*dst++ = '.';
} }
} }
} }