]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/network/networkd-network.c
network: also check that Hostname= is a valid DNS domain name
[thirdparty/systemd.git] / src / network / networkd-network.c
index 429aac5e6c87c2256d657f9f6777841d14a2a778..eb13e9e93dab5297bcb2811c49edb6e272432e6a 100644 (file)
@@ -36,7 +36,12 @@ static int network_config_compare_func(const void *a, const void *b) {
         if (r != 0)
                 return r;
 
-        return y->line - x->line;
+        if (x->line < y->line)
+                return -1;
+        if (x->line > y->line)
+                return 1;
+
+        return 0;
 }
 
 const struct hash_ops network_config_hash_ops = {
@@ -966,7 +971,8 @@ int config_parse_hostname(
                 void *data,
                 void *userdata) {
 
-        char **hostname = data, *hn = NULL;
+        _cleanup_free_ char *hn = NULL;
+        char **hostname = data;
         int r;
 
         assert(filename);
@@ -979,13 +985,20 @@ int config_parse_hostname(
 
         if (!hostname_is_valid(hn, false)) {
                 log_syntax(unit, LOG_ERR, filename, line, 0, "Hostname is not valid, ignoring assignment: %s", rvalue);
-                free(hn);
                 return 0;
         }
 
-        free(*hostname);
-        *hostname = hostname_cleanup(hn);
-        return 0;
+        r = dns_name_is_valid(hn);
+        if (r < 0) {
+                log_syntax(unit, LOG_ERR, filename, line, r, "Failed to check validity of hostname '%s', ignoring assignment: %m", rvalue);
+                return 0;
+        }
+        if (r == 0) {
+                log_syntax(unit, LOG_ERR, filename, line, 0, "Hostname is not a valid DNS domain name, ignoring assignment: %s", rvalue);
+                return 0;
+        }
+
+        return free_and_replace(*hostname, hn);
 }
 
 int config_parse_timezone(