From nobody Sun Feb 8 05:54:50 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1607349331; cv=none; d=zohomail.com; s=zohoarc; b=D+lfbAQtKxyUOjRo8oyf+5XbUdpeSCV7P+6z9mfX8fucPvxuJg+1Vy7eGkRPwue2uErbCjFS9MUlIciTE35XDD5dYrdJEG2oiP4TTP2O1orHL3+g3nxkvA0IKiaNXhP4xKYpCyEa3NaR08E1VRzEO/Z3GriTSOZv4G6K8hoOqTo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1607349331; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=pEsMqx4OOuyRWt4oNaM+FR+1LoT34KkAHUtGzy5Q+0U=; b=R0oTLPQrtpk4f0slsMvtbLukOIaPz0Yuk+vo8BwBpG+Sl6f4z22r/nuP7/iZKatlPd9wgYGxVgzJXIgQ6pNlXm3Yv+s05zNZ807elBI468H70GTorw50Ys5NWAcDMUs9MPFQ8uqymP1JeVtHPJe2KBkziQHYwo0zTe4t3kgrPr0= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1607349331732652.904481627789; Mon, 7 Dec 2020 05:55:31 -0800 (PST) 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-444-Jup9i0epMPyxp4W2rYRqfA-1; Mon, 07 Dec 2020 08:55:28 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A97D01E7CB; Mon, 7 Dec 2020 13:55:22 +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 813E05D9DE; Mon, 7 Dec 2020 13:55:22 +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 485DA50032; Mon, 7 Dec 2020 13:55:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0B7DsxkH012948 for ; Mon, 7 Dec 2020 08:54:59 -0500 Received: by smtp.corp.redhat.com (Postfix) id 837162023197; Mon, 7 Dec 2020 13:54:59 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast05.extmail.prod.ext.rdu2.redhat.com [10.11.55.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7C5D82023198 for ; Mon, 7 Dec 2020 13:54:59 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 66DC7803DD8 for ; Mon, 7 Dec 2020 13:54:59 +0000 (UTC) Received: from mail-qt1-f177.google.com (mail-qt1-f177.google.com [209.85.160.177]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-592-6NYw47jZMeikKIw46KzYzg-1; Mon, 07 Dec 2020 08:54:57 -0500 Received: by mail-qt1-f177.google.com with SMTP id h19so7122447qtq.13 for ; Mon, 07 Dec 2020 05:54:57 -0800 (PST) Received: from rekt.redhat.com ([2804:431:c7c7:c1a:69c1:2b22:e880:fc49]) by smtp.gmail.com with ESMTPSA id n95sm12233701qte.43.2020.12.07.05.54.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Dec 2020 05:54:56 -0800 (PST) X-MC-Unique: Jup9i0epMPyxp4W2rYRqfA-1 X-MC-Unique: 6NYw47jZMeikKIw46KzYzg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=pEsMqx4OOuyRWt4oNaM+FR+1LoT34KkAHUtGzy5Q+0U=; b=JcwQUE7TlU5Jv6xF/BbxnTD+Qj/rrQIE/F+ZAunZ0TCoMHnVw+0RBNzwD5ZLIki0L2 pjVyXVNnHiPV82KJW2IF7GXuxgkGbogErzfzmBbAvZw19Z1q39GBnBQtoQusWMOZV1tg fNG3cMAV6Xj/JETXXti7UMDY4Xhppj/y6yQEWuBrvL04IOH8CcCZmemmAyOkREWfiF9Y HYLxsB3bX1QlIgpDzFixxbGa46M5IVX6p7SAaXiYWRLbffmT1UU9+Sqimh82T4YaGmmC F0z4YqxNJTuTizZ4B7TdGuwSelPfcSg2BXtngz+Fb4E3KC6JEi/3uPQqRjDyPj2HeN3k hr2Q== X-Gm-Message-State: AOAM532SJ9HZPH0bWvtKEivD/gR68d9oO7VskXmQZoBYHyZg60T+O1Os u1j3cTkgeVIN8gJrxE9tLuB51tX150A= X-Google-Smtp-Source: ABdhPJzFzeDc10boWRasNQfPFw3a3oQcAXrjWC3pNCKuRyxu1xWVXy/F527ObMFVK6YDL53KuR/3Eg== X-Received: by 2002:ac8:7604:: with SMTP id t4mr23891029qtq.366.1607349296694; Mon, 07 Dec 2020 05:54:56 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v2 4/9] domain_conf.c: move vendor, product and tray checks to validate callback Date: Mon, 7 Dec 2020 10:54:30 -0300 Message-Id: <20201207135435.884594-5-danielhb413@gmail.com> In-Reply-To: <20201207135435.884594-1-danielhb413@gmail.com> References: <20201207135435.884594-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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.14 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 Content-Type: text/plain; charset="utf-8" The 'tray' check isn't a XML parse specific code and can be pushed to the validate callback, in virDomainDiskDefValidate(). 'vendor' and 'product' string sizes are already checked by the domaincommon.rng schema, but can be of use in the validate callback since not all scenarios will go through the XML parsing. Signed-off-by: Daniel Henrique Barboza --- src/conf/domain_conf.c | 47 ++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 22 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index bc09577e39..e9bafd189f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6115,6 +6115,9 @@ virSecurityDeviceLabelDefValidateXML(virSecurityDevic= eLabelDefPtr *seclabels, } =20 =20 +#define VENDOR_LEN 8 +#define PRODUCT_LEN 16 + static int virDomainDiskDefValidate(const virDomainDef *def, const virDomainDiskDef *disk) @@ -6191,6 +6194,28 @@ virDomainDiskDefValidate(const virDomainDef *def, return -1; } =20 + if (disk->tray_status && + disk->device !=3D VIR_DOMAIN_DISK_DEVICE_FLOPPY && + disk->device !=3D VIR_DOMAIN_DISK_DEVICE_CDROM) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("tray is only valid for cdrom and floppy")); + return -1; + } + + if (disk->vendor && strlen(disk->vendor) > VENDOR_LEN) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("disk vendor is more than %d characters"), + VENDOR_LEN); + return -1; + } + + if (disk->product && strlen(disk->product) > PRODUCT_LEN) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("disk product is more than %d characters"), + PRODUCT_LEN); + return -1; + } + return 0; } =20 @@ -10496,9 +10521,6 @@ virDomainDiskDefParsePrivateData(xmlXPathContextPtr= ctxt, } =20 =20 -#define VENDOR_LEN 8 -#define PRODUCT_LEN 16 - static virDomainDiskDefPtr virDomainDiskDefParseXML(virDomainXMLOptionPtr xmlopt, xmlNodePtr node, @@ -10673,12 +10695,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xml= opt, if (!(vendor =3D virXMLNodeContentString(cur))) return NULL; =20 - if (strlen(vendor) > VENDOR_LEN) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("disk vendor is more than 8 characters")); - return NULL; - } - if (!virStringIsPrintable(vendor)) { virReportError(VIR_ERR_XML_ERROR, "%s", _("disk vendor is not printable string")); @@ -10689,12 +10705,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xml= opt, if (!(product =3D virXMLNodeContentString(cur))) return NULL; =20 - if (strlen(product) > PRODUCT_LEN) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("disk product is more than 16 characters"= )); - return NULL; - } - if (!virStringIsPrintable(product)) { virReportError(VIR_ERR_XML_ERROR, "%s", _("disk product is not printable string")); @@ -10825,13 +10835,6 @@ virDomainDiskDefParseXML(virDomainXMLOptionPtr xml= opt, _("unknown disk tray status '%s'"), tray); return NULL; } - - if (def->device !=3D VIR_DOMAIN_DISK_DEVICE_FLOPPY && - def->device !=3D VIR_DOMAIN_DISK_DEVICE_CDROM) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("tray is only valid for cdrom and floppy")); - return NULL; - } } =20 if (removable) { --=20 2.26.2