dhcp: merge branch 'bg/dhcp-invalid-hostname'

https://bugzilla.redhat.com/show_bug.cgi?id=1744427
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/310
(cherry picked from commit a5f22dbc5d)
This commit is contained in:
Beniamino Galvani 2020-02-10 09:44:20 +01:00
commit ee8ae9ae43
3 changed files with 29 additions and 3 deletions

View file

@ -22,9 +22,10 @@
#include "nm-sd-adapt-shared.h"
#include "path-util.h"
#include "hexdecoct.h"
#include "dns-domain.h"
#include "hexdecoct.h"
#include "hostname-util.h"
#include "path-util.h"
/*****************************************************************************/
@ -52,7 +53,7 @@ nm_sd_utils_path_startswith (const char *path, const char *prefix)
/*****************************************************************************/
gboolean
int
nm_sd_utils_unbase64char (char ch, gboolean accept_padding_equal)
{
if ( ch == '='
@ -96,3 +97,13 @@ int nm_sd_dns_name_to_wire_format (const char *domain,
{
return dns_name_to_wire_format (domain, buffer, len, canonical);
}
int nm_sd_dns_name_is_valid (const char *s)
{
return dns_name_is_valid (s);
}
gboolean nm_sd_hostname_is_valid (const char *s, bool allow_trailing_dot)
{
return hostname_is_valid (s, allow_trailing_dot);
}

View file

@ -44,4 +44,7 @@ int nm_sd_dns_name_to_wire_format (const char *domain,
size_t len,
gboolean canonical);
int nm_sd_dns_name_is_valid (const char *s);
gboolean nm_sd_hostname_is_valid(const char *s, bool allow_trailing_dot);
#endif /* __NM_SD_UTILS_SHARED_H__ */

View file

@ -32,6 +32,7 @@
#include <stdio.h>
#include "nm-glib-aux/nm-dedup-multi.h"
#include "systemd/nm-sd-utils-shared.h"
#include "nm-config.h"
#include "NetworkManagerUtils.h"
@ -251,6 +252,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);