render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
d76c62
From 3ff27fe469c36e5655231f6759150350b17de298 Mon Sep 17 00:00:00 2001
d76c62
Message-Id: <3ff27fe469c36e5655231f6759150350b17de298@dist-git>
d76c62
From: Michal Privoznik <mprivozn@redhat.com>
d76c62
Date: Fri, 13 Mar 2020 13:08:09 +0100
d76c62
Subject: [PATCH] conf: Don't generate machine names with a dot
d76c62
MIME-Version: 1.0
d76c62
Content-Type: text/plain; charset=UTF-8
d76c62
Content-Transfer-Encoding: 8bit
d76c62
d76c62
According to the linked BZ, machined expects either valid
d76c62
hostname or valid FQDN (see systemd commit
d76c62
v239-3092-gd65652f1f2). While in case of multiple dots, a
d76c62
trailing one doesn't violate FQDN, it does violate the rule in
d76c62
case of something simple, like "domain.". But it's safe to remove
d76c62
it in both cases.
d76c62
d76c62
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1808499
d76c62
Fixes: 45464db8ba502764cf37ec9335770248bdb3d9a8
d76c62
d76c62
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
d76c62
Reviewed-by: Ján Tomko <jtomko@redhat.com>
d76c62
(cherry picked from commit 2695191a44eb7375225b4ad073825ed3563a172a)
d76c62
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
d76c62
Message-Id: <355e05e31ec98522fa0e03a0c2c7af8ca097070d.1584101247.git.mprivozn@redhat.com>
d76c62
Reviewed-by: Ján Tomko <jtomko@redhat.com>
d76c62
---
d76c62
 src/conf/domain_conf.c | 14 +++++++-------
d76c62
 tests/virsystemdtest.c |  5 +++--
d76c62
 2 files changed, 10 insertions(+), 9 deletions(-)
d76c62
d76c62
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
d76c62
index 4b297c96bc..b3c4084c38 100644
d76c62
--- a/src/conf/domain_conf.c
d76c62
+++ b/src/conf/domain_conf.c
d76c62
@@ -30688,20 +30688,20 @@ static void
d76c62
 virDomainMachineNameAppendValid(virBufferPtr buf,
d76c62
                                 const char *name)
d76c62
 {
d76c62
-    bool skip_dot = false;
d76c62
+    bool skip = true;
d76c62
 
d76c62
     for (; *name; name++) {
d76c62
         if (strlen(virBufferCurrentContent(buf)) >= 64)
d76c62
             break;
d76c62
 
d76c62
-        if (*name == '.') {
d76c62
-            if (!skip_dot)
d76c62
+        if (*name == '.' || *name == '-') {
d76c62
+            if (!skip)
d76c62
                 virBufferAddChar(buf, *name);
d76c62
-            skip_dot = true;
d76c62
+            skip = true;
d76c62
             continue;
d76c62
         }
d76c62
 
d76c62
-        skip_dot = false;
d76c62
+        skip = false;
d76c62
 
d76c62
         if (!strchr(HOSTNAME_CHARS, *name))
d76c62
             continue;
d76c62
@@ -30709,8 +30709,8 @@ virDomainMachineNameAppendValid(virBufferPtr buf,
d76c62
         virBufferAddChar(buf, *name);
d76c62
     }
d76c62
 
d76c62
-    /* trailing dashes are not allowed */
d76c62
-    virBufferTrimChars(buf, "-");
d76c62
+    /* trailing dashes or dots are not allowed */
d76c62
+    virBufferTrimChars(buf, "-.");
d76c62
 }
d76c62
 
d76c62
 #undef HOSTNAME_CHARS
d76c62
diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c
d76c62
index 26876850b8..eb510b40e4 100644
d76c62
--- a/tests/virsystemdtest.c
d76c62
+++ b/tests/virsystemdtest.c
d76c62
@@ -733,7 +733,7 @@ mymain(void)
d76c62
     TEST_MACHINE("demo", 1, "qemu-1-demo");
d76c62
     TEST_MACHINE("demo-name", 2, "qemu-2-demo-name");
d76c62
     TEST_MACHINE("demo!name", 3, "qemu-3-demoname");
d76c62
-    TEST_MACHINE(".demo", 4, "qemu-4-.demo");
d76c62
+    TEST_MACHINE(".demo", 4, "qemu-4-demo");
d76c62
     TEST_MACHINE("bull\U0001f4a9", 5, "qemu-5-bull");
d76c62
     TEST_MACHINE("demo..name", 6, "qemu-6-demo.name");
d76c62
     TEST_MACHINE("12345678901234567890123456789012345678901234567890123456789", 7,
d76c62
@@ -743,7 +743,8 @@ mymain(void)
d76c62
     TEST_MACHINE("kstest-network-device-default-httpks_(c9eed63e-981e-48ec-acdc-56b3f8c5f678)", 100,
d76c62
                  "qemu-100-kstest-network-device-default-httpksc9eed63e-981e-48ec");
d76c62
     TEST_MACHINE("kstest-network-device-default-httpks_(c9eed63e-981e-48ec--cdc-56b3f8c5f678)", 10,
d76c62
-                 "qemu-10-kstest-network-device-default-httpksc9eed63e-981e-48ec");
d76c62
+                 "qemu-10-kstest-network-device-default-httpksc9eed63e-981e-48ec-c");
d76c62
+    TEST_MACHINE("demo.-.test.", 11, "qemu-11-demo.test");
d76c62
 
d76c62
 # define TESTS_PM_SUPPORT_HELPER(name, function) \
d76c62
     do { \
d76c62
-- 
d76c62
2.25.1
d76c62