summaryrefslogtreecommitdiff
path: root/src/libsystemd-network
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-11-18 12:33:14 +0100
committerLennart Poettering <lennart@poettering.net>2016-11-21 22:47:47 +0100
commit17f6ed4d5956f4e74056ae976b638dbba33c2844 (patch)
tree33bed0338e7aa87259bc1672341bc415401261ae /src/libsystemd-network
parentc5066640a1a82bc74f538fe9d2ecc52ea81613b3 (diff)
downloadsystemd-17f6ed4d5956f4e74056ae976b638dbba33c2844.tar.gz
sd-dhcp: permit unsetting the hostname again
Let's handle NULL hostnames (for unsetting it) before we validate the name.
Diffstat (limited to 'src/libsystemd-network')
-rw-r--r--src/libsystemd-network/sd-dhcp-client.c14
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;