]> git.ipfire.org Git - thirdparty/systemd.git/commit - src/resolve/resolved-dns-rr.c
resolve: reject host names with leading or trailing dashes in /etc/hosts
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 21 Nov 2018 21:58:13 +0000 (22:58 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 10 Dec 2018 08:56:56 +0000 (09:56 +0100)
commit7470cc4c73c3736b93070ec01369e449e40a7cb3
tree7f996421d5fb688a7f48f1f6b4d623f06b9f1990
parentbd0052777981044cf54a1e9d6e3acb1c3d813656
resolve: reject host names with leading or trailing dashes in /etc/hosts

https://tools.ietf.org/html/rfc1035#section-2.3.1 says (approximately)
that only letters, numbers, and non-leading non-trailing dashes are allowed
(for entries with A/AAAA records). We set no restrictions.

hosts(5) says:
> Host names may contain only alphanumeric characters, minus signs ("-"), and
> periods (".").  They must begin with an alphabetic character and end with an
> alphanumeric character.

nss-files follows those rules, and will ignore names in /etc/hosts that do not
follow this rule.

Let's follow the documented rules for /etc/hosts. In particular, this makes us
consitent with nss-files, reducing surprises for the user.

I'm pretty sure we should apply stricter filtering to names received over DNS
and LLMNR and MDNS, but it's a bigger project, because the rules differ
depepending on which level the label appears (rules for top-level names are
stricter), and this patch takes the minimalistic approach and only changes
behaviour for /etc/hosts.

Escape syntax is also disallowed in /etc/hosts, even if the resulting character
would be allowed. Other tools that parse /etc/hosts do not support this, and
there is no need to use it because no allowed characters benefit from escaping.
15 files changed:
src/libsystemd-network/ndisc-router.c
src/libsystemd-network/sd-dhcp-lease.c
src/network/networkd-network.c
src/resolve/resolved-bus.c
src/resolve/resolved-dns-dnssec.c
src/resolve/resolved-dns-packet.c
src/resolve/resolved-dns-rr.c
src/resolve/resolved-dns-search-domain.c
src/resolve/resolved-dnssd.c
src/resolve/resolved-etc-hosts.c
src/resolve/resolved-manager.c
src/resolve/test-resolved-etc-hosts.c
src/shared/dns-domain.c
src/shared/dns-domain.h
src/test/test-dns-domain.c