render / rpms / libvirt

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