core: accept hostnames longer than 64 characters from DNS lookup

When resolving the system hostname from DNS lookup, we use
nm_utils_validate_hostname() which checks that the result is a valid
hostname. A valid hostname is at most 64 characters on Linux. Anything
longer is discarded.

However, the reverse DNS lookup doesn't return a hostname, it returns
a DNS name. The DNS name can have multiple labels, each limited to 63
characters. The maximum length of the DNS name is 253 characters.

If the result is longer than 64 characters because it has multiple
labels, we should still accept it, provided that it is a valid DNS
name. Then when setting the hostname in the system, only the first
label will be kept.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/2243

Resolves: https://issues.redhat.com/browse/RHEL-104357
(cherry picked from commit b019883a9a)
This commit is contained in:
Beniamino Galvani 2025-07-17 18:30:30 +02:00
parent e4f321c307
commit 4deee49763

View file

@ -18691,7 +18691,7 @@ hostname_dns_lookup_callback(GObject *source, GAsyncResult *result, gpointer use
gboolean valid;
resolver->hostname = g_steal_pointer(&output);
valid = nm_utils_validate_hostname(resolver->hostname);
valid = nm_sd_dns_name_is_valid(resolver->hostname);
_LOGD(LOGD_DNS,
"hostname-from-dns: ipv%c resolver %s: lookup successful for %s, result %s%s%s%s",