[PATCH] Resolver: added support for domain names with a trailing dot

Ruslan Ermilov ru at nginx.com
Fri Jan 10 19:10:06 UTC 2014


On Wed, Jan 08, 2014 at 11:59:42AM -0800, Yichun Zhang (agentzh) wrote:
> We've noticed that the builtin resolver in Nginx cannot handle domain
> names with a trailing dot (like "agentzh.org.") and just return the
> error "Host not found". The following patch attempts a fix.

There's no such thing as domain names with a trailing dot,
with one exception of the root domain name.

Specifying the dot at the end of a domain name is the feature
of the system resolver(3); see hostname(7) manpage on Linux,
BSD or MAC for details.

Since resolver in nginx doesn't support $HOSTALIASES, nor
does it support searching through the list of domain names,
there's no much point in specifying domain names with the
trailing dot.  It similarly doesn't support "hostnames" like
"127.1" or "0x7f000001" which the system resolver does.

So I must ask.  Why do you think that resolver in nginx
should ever support names with a trailing dot?

> # HG changeset patch
> # User Yichun Zhang <agentzh at gmail.com>
> # Date 1389209699 28800
> # Node ID 3d10680c0399cb8d2e3b601412df0495ffaab4a5
> # Parent  c0d6eae5a1c5d16cf6a9d6a3a73656972f838eab
> Resolver: added support for domain names with a trailing dot.
> 
> diff -r c0d6eae5a1c5 -r 3d10680c0399 src/core/ngx_resolver.c
> --- a/src/core/ngx_resolver.c	Fri Dec 13 20:49:52 2013 +0400
> +++ b/src/core/ngx_resolver.c	Wed Jan 08 11:34:59 2014 -0800
> @@ -467,6 +467,10 @@
>      ngx_resolver_ctx_t   *next;
>      ngx_resolver_node_t  *rn;
>  
> +    if (ctx->name.len > 0 && ctx->name.data[ctx->name.len - 1] == '.') {
> +        ctx->name.len--;
> +    }
> +
>      ngx_strlow(ctx->name.data, ctx->name.data, ctx->name.len);
>  
>      hash = ngx_crc32_short(ctx->name.data, ctx->name.len);

Regarding the patch, it would make more sense to strip the
trailing dot once on entry, in ngx_resolve_name(), not in
ngx_resolve_name_locked() which is also called internally.



More information about the nginx-devel mailing list