From nobody Sun May 5 14:14:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1624630323; cv=none; d=zohomail.com; s=zohoarc; b=J6h/qhCyULr6U+hfQjIbkpmLx70lW94gTwnwLE/DyTs7NQzt3a9Q6QzRUv6awRprVMfXcFduQhqp0xshsH69p+Dbq8Y6NP+FUIAvE2avX2Xs7VKsQGWIZzBZIG+PZKWNB8QiDAldEgG/JOl8Hxkhr+akNkcXAn4P+F+orXp4wQ8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1624630323; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=fZy4yCnkawqbcNjXC/edvcDSSuEP6JKq9dd7V07VxDs=; b=jjivmJV566o8obwZ8ScxH/pGqYhnfi4Jn5/c8m1W9BnP6npB3EhVO3WOY4awUkpd1qsBxKHfUocaS9jkHvN8K6fVMF1mdTN6Rnwnbno3HFxRTtXLIjrZxAMfVG4LpbUdVI8b830lJJ/wuFtU/F1bHAUp8eOcPGbw5y7nckP3Svs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1624630323068108.5372151813441; Fri, 25 Jun 2021 07:12:03 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-604-eFo7-4sINI6ZRXNvaxGXNw-1; Fri, 25 Jun 2021 10:11:09 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D7DDB100CA88; Fri, 25 Jun 2021 14:11:02 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2CD355D6A8; Fri, 25 Jun 2021 14:11:00 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id B06B54A702; Fri, 25 Jun 2021 14:10:55 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 15PEAsgG016791 for ; Fri, 25 Jun 2021 10:10:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2A1975D6A8; Fri, 25 Jun 2021 14:10:54 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.194.21]) by smtp.corp.redhat.com (Postfix) with ESMTP id A24595D6AB for ; Fri, 25 Jun 2021 14:10:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624630322; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=fZy4yCnkawqbcNjXC/edvcDSSuEP6JKq9dd7V07VxDs=; b=MAxYA0Ryj/3y1ATpnfvw2aSf6Sp66noPoEKudhR2NKBiT81BIx0KzErxFMWABPZl748gUe MSSPbX5hbIqNKv3MbaVVQF6Iva7wPaTxMgrugc1HkU++qguNf0CnZM+b3IlWJmw27JTLsm CpLGPHOSjkWelioBYCEZ00z1Z+sMbwo= X-MC-Unique: eFo7-4sINI6ZRXNvaxGXNw-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH] virDomainMachineNameAppendValid: Handle special characters better Date: Fri, 25 Jun 2021 16:10:50 +0200 Message-Id: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" 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=3D1948433 Signed-off-by: Michal Privoznik Reviewed-by: Daniel Henrique Barboza --- src/hypervisor/domain_driver.c | 8 ++++---- tests/virsystemdtest.c | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index f7d49bc38a..29e11c0447 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -63,18 +63,18 @@ virDomainMachineNameAppendValid(virBuffer *buf, break; =20 if (*name =3D=3D '.' || *name =3D=3D '-') { - if (!skip) + if (!skip) { virBufferAddChar(buf, *name); - skip =3D true; + skip =3D true; + } continue; } =20 - skip =3D false; - if (!strchr(HOSTNAME_CHARS, *name)) continue; =20 virBufferAddChar(buf, *name); + skip =3D false; } =20 /* trailing dashes or dots are not allowed */ diff --git a/tests/virsystemdtest.c b/tests/virsystemdtest.c index f1c9a4ee5f..a09b428a8a 100644 --- a/tests/virsystemdtest.c +++ b/tests/virsystemdtest.c @@ -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~!@#$%^&*_=3D+,?><= :;|.\"[]()`\\-m", + NULL, 1, "qemu-1-Auto-esx7.0-rhel7.9-special-characters.m= "); =20 # define TESTS_PM_SUPPORT_HELPER(name, function) \ do { \ --=20 2.31.1