From 2da4d54ac3e58b94a915d1fd0c488610b855c6fa Mon Sep 17 00:00:00 2001 From: Beniamino Galvani Date: Thu, 17 Oct 2019 17:40:29 +0200 Subject: [PATCH] dhcp: ignore hostname when invalid The hostname used for DHCP can be the one obtained from the hostnamed service and is not guaranteed to be valid, at least with systemd 239. Instead of sending an invalid DHCP option to the server or failing due to later checks in clients, ignore the hostname and log a warning when it is invalid. https://bugzilla.redhat.com/show_bug.cgi?id=1744427 --- src/dhcp/nm-dhcp-manager.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/dhcp/nm-dhcp-manager.c b/src/dhcp/nm-dhcp-manager.c index a27f5572bb..2458f6c616 100644 --- a/src/dhcp/nm-dhcp-manager.c +++ b/src/dhcp/nm-dhcp-manager.c @@ -17,6 +17,7 @@ #include #include "nm-glib-aux/nm-dedup-multi.h" +#include "systemd/nm-sd-utils-shared.h" #include "nm-config.h" #include "NetworkManagerUtils.h" @@ -252,6 +253,17 @@ client_start (NMDhcpManager *self, g_return_val_if_reached (NULL) ; } + if (hostname) { + if ( (hostname_use_fqdn && !nm_sd_dns_name_is_valid (hostname)) + || (!hostname_use_fqdn && !nm_sd_hostname_is_valid (hostname, FALSE))) { + nm_log_warn (LOGD_DHCP , "dhcp%c: %s '%s' is invalid, will be ignored", + nm_utils_addr_family_to_char (addr_family), + hostname_use_fqdn ? "FQDN" : "hostname", + hostname); + hostname = NULL; + } + } + nm_assert (g_bytes_get_size (hwaddr) == g_bytes_get_size (bcast_hwaddr)); priv = NM_DHCP_MANAGER_GET_PRIVATE (self);