From: Lennart Poettering Date: Fri, 18 Nov 2016 11:33:14 +0000 (+0100) Subject: sd-dhcp: permit unsetting the hostname again X-Git-Tag: v234~804^2~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=17f6ed4d5956f4e74056ae976b638dbba33c2844;p=platform%2Fupstream%2Fsystemd.git sd-dhcp: permit unsetting the hostname again Let's handle NULL hostnames (for unsetting it) before we validate the name. --- diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c index 6475da2..9716168 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;