diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index d2d97daf80..f8a8d133ba 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -30927,20 +30927,20 @@ static void virDomainMachineNameAppendValid(virBufferPtr buf, const char *name) { - bool skip_dot = false; + bool skip = true; for (; *name; name++) { if (strlen(virBufferCurrentContent(buf)) >= 64) break; - if (*name == '.') { - if (!skip_dot) + if (*name == '.' || *name == '-') { + if (!skip) virBufferAddChar(buf, *name); - skip_dot = true; + skip = true; continue; } - skip_dot = false; + skip = false; if (!strchr(HOSTNAME_CHARS, *name)) continue; @@ -30948,8 +30948,8 @@ virDomainMachineNameAppendValid(virBufferPtr buf, virBufferAddChar(buf, *name); } - /* trailing dashes are not allowed */ - virBufferTrimChars(buf, "-"); + /* trailing dashes or dots are not allowed */ + virBufferTrimChars(buf, "-."); } #undef HOSTNAME_CHARS diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c index 1e36298189..fa0980c845 100644 --- a/tests/virsystemdtest.c +++ b/tests/virsystemdtest.c @@ -736,7 +736,7 @@ mymain(void) TEST_MACHINE("demo", 1, "qemu-1-demo"); TEST_MACHINE("demo-name", 2, "qemu-2-demo-name"); TEST_MACHINE("demo!name", 3, "qemu-3-demoname"); - TEST_MACHINE(".demo", 4, "qemu-4-.demo"); + TEST_MACHINE(".demo", 4, "qemu-4-demo"); TEST_MACHINE("bull\U0001f4a9", 5, "qemu-5-bull"); TEST_MACHINE("demo..name", 6, "qemu-6-demo.name"); TEST_MACHINE("12345678901234567890123456789012345678901234567890123456789", 7, @@ -746,7 +746,8 @@ mymain(void) TEST_MACHINE("kstest-network-device-default-httpks_(c9eed63e-981e-48ec-acdc-56b3f8c5f678)", 100, "qemu-100-kstest-network-device-default-httpksc9eed63e-981e-48ec"); TEST_MACHINE("kstest-network-device-default-httpks_(c9eed63e-981e-48ec--cdc-56b3f8c5f678)", 10, - "qemu-10-kstest-network-device-default-httpksc9eed63e-981e-48ec"); + "qemu-10-kstest-network-device-default-httpksc9eed63e-981e-48ec-c"); + TEST_MACHINE("demo.-.test.", 11, "qemu-11-demo.test"); # define TESTS_PM_SUPPORT_HELPER(name, function) \ do { \