diff options
Diffstat (limited to 'src/libsystemd-network/sd-dhcp-client.c')
-rw-r--r-- | src/libsystemd-network/sd-dhcp-client.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c index 6475da2c2a..9716168c1e 100644 --- a/src/libsystemd-network/sd-dhcp-client.c +++ b/src/libsystemd-network/sd-dhcp-client.c @@ -390,17 +390,21 @@ int sd_dhcp_client_set_hostname( assert_return(client, -EINVAL); + if (!hostname) { + client->hostname = mfree(client->hostname); + return 0; + } + + /* Refuse hostnames that neither qualify as DNS nor as Linux hosntames */ if (!hostname_is_valid(hostname, false) && !dns_name_is_valid(hostname)) return -EINVAL; if (streq_ptr(client->hostname, hostname)) return 0; - if (hostname) { - new_hostname = strdup(hostname); - if (!new_hostname) - return -ENOMEM; - } + new_hostname = strdup(hostname); + if (!new_hostname) + return -ENOMEM; free(client->hostname); client->hostname = new_hostname; |