]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virDomainMachineNameAppendValid: Handle special characters better
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 25 Jun 2021 13:51:52 +0000 (15:51 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 7 Jul 2021 14:23:37 +0000 (16:23 +0200)
When constructing guest name for machined we have to be very
cautious as machined expects a name that's basically a valid URI.
Therefore, if there's a dot it has to be followed by a letter or
a number. And if there's a sequence of two or more dashes they
should be joined into a single dash. These rules are implemented
in virDomainMachineNameAppendValid(). There's the @skip variable
which is supposed to track whether it is safe to append a dot or
a dash into name. However, the variable is set to false (meaning
it is safe to append a dot or a dash) even if the current
character we are processing is not in the set of allowed
characters (and thus skipped over).

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1948433
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
src/hypervisor/domain_driver.c
tests/virsystemdtest.c

index f7d49bc38a9b9d3e3ada1ed2081877648beb2044..29e11c04474a644a4a3186d7f353395a978767c2 100644 (file)
@@ -63,18 +63,18 @@ virDomainMachineNameAppendValid(virBuffer *buf,
             break;
 
         if (*name == '.' || *name == '-') {
-            if (!skip)
+            if (!skip) {
                 virBufferAddChar(buf, *name);
-            skip = true;
+                skip = true;
+            }
             continue;
         }
 
-        skip = false;
-
         if (!strchr(HOSTNAME_CHARS, *name))
             continue;
 
         virBufferAddChar(buf, *name);
+        skip = false;
     }
 
     /* trailing dashes or dots are not allowed */
index f1c9a4ee5fb08b16be9dbf9806238e6148fe2b46..a09b428a8ae5ef781bdbe38944a592bc29d5b754 100644 (file)
@@ -736,6 +736,9 @@ mymain(void)
     TEST_MACHINE("demo.-.test.", NULL, 11, "qemu-11-demo.test");
     TEST_MACHINE("demo", "/tmp/root1", 1, "qemu-embed-0991f456-1-demo");
     TEST_MACHINE("demo", "/tmp/root2", 1, "qemu-embed-95d47ff5-1-demo");
+    TEST_MACHINE("|.-m", NULL, 1, "qemu-1-m");
+    TEST_MACHINE("Auto-esx7.0-rhel7.9-special-characters~!@#$%^&*_=+,?><:;|.\"[]()`\\-m",
+                 NULL, 1, "qemu-1-Auto-esx7.0-rhel7.9-special-characters.m");
 
 # define TESTS_PM_SUPPORT_HELPER(name, function) \
     do { \