mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-06-10 14:58:30 +02:00
dhcp/dhclient: validate hostname before pasting it into dhclient config
This commit is contained in:
parent
af9c1baaf0
commit
760da07a22
1 changed files with 16 additions and 0 deletions
|
|
@ -221,6 +221,16 @@ find_existing_config(NMDhcpDhclient *self, int addr_family, const char *iface, c
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
_dhclient_hostname_is_valid(const char *hostname)
|
||||
{
|
||||
for (const char *p = hostname; *p; p++) {
|
||||
if (*p == '"' || *p == '\\' || *p < 0x20)
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* NM provides interface-specific options; thus the same dhclient config
|
||||
* file cannot be used since DHCP transactions can happen in parallel.
|
||||
* Since some distros don't have default per-interface dhclient config files,
|
||||
|
|
@ -251,6 +261,12 @@ create_dhclient_config(NMDhcpDhclient *self,
|
|||
|
||||
g_return_val_if_fail(iface != NULL, NULL);
|
||||
|
||||
if (hostname && !_dhclient_hostname_is_valid(hostname)) {
|
||||
_LOGW("hostname '%s' contains unsafe characters for dhclient config, will be ignored",
|
||||
hostname);
|
||||
hostname = NULL;
|
||||
}
|
||||
|
||||
new_path = g_strdup_printf(NMSTATEDIR "/dhclient%s-%s.conf",
|
||||
_addr_family_to_path_part(addr_family),
|
||||
iface);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue