From nobody Sat Apr 20 15:40:01 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=1619522001; cv=none; d=zohomail.com; s=zohoarc; b=DK5G1W7HVifK/x0ikp5bSydCWY7tDnFpPek+3Kcjg9ERWfmcVU6weNFt72OEnyEcMXx5lIZ/9xuo2q40XjCKwsZ/J79DNBZ86pqiIe1Wx9U73F/jZHMSZPpmZDttTn5yK8ttVZKPMEagnBfKM/RJ/Rg/yHGcAbj9jH+KyZsAodg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619522001; 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=jc7Yc/5pioe0CKvg8dQtnz2LSsS+03dKPtQHidRIzO8=; b=VcVSkQjkL8OmoKV0h8p3pcalSdd4CVQeiI0ytBdhOXbJxPIC7GCZm9wa6eCgxtj8KjLBA7vWFD8Jsg97qwCmooehRdwoG+Yh6syBackpI7UKfeVbVGZPi0ObOpG49qcV6EiYyX/vay0ZeX3yrX46QgujCAUa8Q7/N85OrXlAkvM= 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) header.from= 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 1619522001503829.8509569429434; Tue, 27 Apr 2021 04:13:21 -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-127-BzfLi5ifPxmqa4Gml1pezQ-1; Tue, 27 Apr 2021 07:13:17 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 73AF180EF81; Tue, 27 Apr 2021 11:13:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0B3D36910A; Tue, 27 Apr 2021 11:13:09 +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 B5D8918095C9; Tue, 27 Apr 2021 11:13:06 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13RBD4BB009653 for ; Tue, 27 Apr 2021 07:13:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9740253CC6; Tue, 27 Apr 2021 11:13:04 +0000 (UTC) Received: from work.redhat.com (ovpn-113-91.ams2.redhat.com [10.36.113.91]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C72A60CFB; Tue, 27 Apr 2021 11:13:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619522000; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=jc7Yc/5pioe0CKvg8dQtnz2LSsS+03dKPtQHidRIzO8=; b=LYU7DXynPoUUvr05dxVBtqtBIKsW0m4nCz+kn4Qc0f03L1Zm+1yma75FPBQSTfSWsykdTB h4qvTUFo7LTgr5mjN6lcDMZwgiP28cqOvdaM8zHGVW5dZH0Tywxa922+3lpIQ86q1J7Ehn w8FmOHxrJ0Dy8xOu7jBgJ2RYktQZ+hU= X-MC-Unique: BzfLi5ifPxmqa4Gml1pezQ-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 1/6] virDomainGraphicsDefParseXMLSpice: Use virXMLProp* Date: Tue, 27 Apr 2021 13:12:52 +0200 Message-Id: <20210427111257.157406-2-twiederh@redhat.com> In-Reply-To: <20210427111257.157406-1-twiederh@redhat.com> References: <20210427111257.157406-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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.11 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" Signed-off-by: Tim Wiederhake Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 251 ++++++++++------------------------------- 1 file changed, 59 insertions(+), 192 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9d98f487ea..822426bc4e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -12905,49 +12905,30 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraphi= csDef *def, unsigned int flags) { xmlNodePtr cur; - int defaultModeVal; - g_autofree char *port =3D virXMLPropString(node, "port"); - g_autofree char *tlsPort =3D virXMLPropString(node, "tlsPort"); g_autofree char *autoport =3D virXMLPropString(node, "autoport"); - g_autofree char *defaultMode =3D virXMLPropString(node, "defaultMode"); =20 if (virDomainGraphicsListensParseXML(def, node, ctxt, flags) < 0) return -1; =20 - if (port) { - if (virStrToLong_i(port, NULL, 10, &def->data.spice.port) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse spice port %s"), port); - return -1; - } - } else { - def->data.spice.port =3D 0; - } + def->data.spice.port =3D 0; + if (virXMLPropInt(node, "port", 10, VIR_XML_PROP_NONE, + &def->data.spice.port) < 0) + return -1; =20 - if (tlsPort) { - if (virStrToLong_i(tlsPort, NULL, 10, &def->data.spice.tlsPort) < = 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("cannot parse spice tlsPort %s"), tlsPort); - return -1; - } - } else { - def->data.spice.tlsPort =3D 0; - } + def->data.spice.tlsPort =3D 0; + if (virXMLPropInt(node, "tlsPort", 10, VIR_XML_PROP_NONE, + &def->data.spice.tlsPort) < 0) + return -1; =20 if (STREQ_NULLABLE(autoport, "yes")) def->data.spice.autoport =3D true; =20 def->data.spice.defaultMode =3D VIR_DOMAIN_GRAPHICS_SPICE_CHANNEL_MODE= _ANY; =20 - if (defaultMode) { - if ((defaultModeVal =3D virDomainGraphicsSpiceChannelModeTypeFromS= tring(defaultMode)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown default spice channel mode %s"), - defaultMode); - return -1; - } - def->data.spice.defaultMode =3D defaultModeVal; - } + if (virXMLPropEnum(node, "defaultMode", + virDomainGraphicsSpiceChannelModeTypeFromString, + VIR_XML_PROP_NONE, &def->data.spice.defaultMode) < = 0) + return -1; =20 if (def->data.spice.port =3D=3D -1 && def->data.spice.tlsPort =3D=3D -= 1) { /* Legacy compat syntax, used -1 for auto-port */ @@ -12969,200 +12950,86 @@ virDomainGraphicsDefParseXMLSpice(virDomainGraph= icsDef *def, while (cur !=3D NULL) { if (cur->type =3D=3D XML_ELEMENT_NODE) { if (virXMLNodeNameEqual(cur, "channel")) { - int nameval, modeval; - g_autofree char *name =3D NULL; - g_autofree char *mode =3D NULL; - - name =3D virXMLPropString(cur, "name"); - mode =3D virXMLPropString(cur, "mode"); + virDomainGraphicsSpiceChannelName name; + virDomainGraphicsSpiceChannelMode mode; =20 - if (!name || !mode) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("spice channel missing name/mode")); + if (virXMLPropEnum(cur, "name", + virDomainGraphicsSpiceChannelNameTypeFr= omString, + VIR_XML_PROP_REQUIRED, &name) < 0) return -1; - } =20 - if ((nameval =3D virDomainGraphicsSpiceChannelNameTypeFrom= String(name)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown spice channel name %s"), - name); - return -1; - } - if ((modeval =3D virDomainGraphicsSpiceChannelModeTypeFrom= String(mode)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown spice channel mode %s"), - mode); + if (virXMLPropEnum(cur, "mode", + virDomainGraphicsSpiceChannelModeTypeFr= omString, + VIR_XML_PROP_REQUIRED, &mode) < 0) return -1; - } =20 - def->data.spice.channels[nameval] =3D modeval; + def->data.spice.channels[name] =3D mode; } else if (virXMLNodeNameEqual(cur, "image")) { - int compressionVal; - g_autofree char *compression =3D virXMLPropString(cur, "co= mpression"); + virDomainGraphicsSpiceImageCompression compression; =20 - if (!compression) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("spice image missing compression")); + if (virXMLPropEnum(cur, "compression", + virDomainGraphicsSpiceImageCompressionT= ypeFromString, + VIR_XML_PROP_NONZERO, &compression) < 0) return -1; - } =20 - if ((compressionVal =3D - virDomainGraphicsSpiceImageCompressionTypeFromString(= compression)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown spice image compression %s"), - compression); - return -1; - } - - def->data.spice.image =3D compressionVal; + def->data.spice.image =3D compression; } else if (virXMLNodeNameEqual(cur, "jpeg")) { - int compressionVal; - g_autofree char *compression =3D virXMLPropString(cur, "co= mpression"); + virDomainGraphicsSpiceJpegCompression compression; =20 - if (!compression) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("spice jpeg missing compression")); + if (virXMLPropEnum(cur, "compression", + virDomainGraphicsSpiceJpegCompressionTy= peFromString, + VIR_XML_PROP_NONZERO, &compression) < 0) return -1; - } =20 - if ((compressionVal =3D - virDomainGraphicsSpiceJpegCompressionTypeFromString(c= ompression)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown spice jpeg compression %s"), - compression); - return -1; - } - - def->data.spice.jpeg =3D compressionVal; + def->data.spice.jpeg =3D compression; } else if (virXMLNodeNameEqual(cur, "zlib")) { - int compressionVal; - g_autofree char *compression =3D virXMLPropString(cur, "co= mpression"); - - if (!compression) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("spice zlib missing compression")); - return -1; - } + virDomainGraphicsSpiceZlibCompression compression; =20 - if ((compressionVal =3D - virDomainGraphicsSpiceZlibCompressionTypeFromString(c= ompression)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown spice zlib compression %s"), - compression); + if (virXMLPropEnum(cur, "compression", + virDomainGraphicsSpiceZlibCompressionTy= peFromString, + VIR_XML_PROP_REQUIRED, &compression) < = 0) return -1; - } =20 - def->data.spice.zlib =3D compressionVal; + def->data.spice.zlib =3D compression; } else if (virXMLNodeNameEqual(cur, "playback")) { - int compressionVal; - g_autofree char *compression =3D virXMLPropString(cur, "co= mpression"); - - if (!compression) { - virReportError(VIR_ERR_INTERNAL_ERROR, "%s", - _("spice playback missing compression")= ); - return -1; - } - - if ((compressionVal =3D - virTristateSwitchTypeFromString(compression)) <=3D 0)= { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("unknown spice playback compression")= ); + if (virXMLPropTristateSwitch(cur, "compression", + VIR_XML_PROP_NONZERO, + &def->data.spice.playback) < = 0) return -1; - } =20 - def->data.spice.playback =3D compressionVal; } else if (virXMLNodeNameEqual(cur, "streaming")) { - int modeVal; - g_autofree char *mode =3D virXMLPropString(cur, "mode"); + virDomainGraphicsSpiceStreamingMode mode; =20 - if (!mode) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("spice streaming missing mode")); - return -1; - } - if ((modeVal =3D - virDomainGraphicsSpiceStreamingModeTypeFromString(mod= e)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("unknown spice streaming mode")); + if (virXMLPropEnum(cur, "mode", + virDomainGraphicsSpiceStreamingModeType= FromString, + VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NO= NZERO, + &mode) < 0) return -1; - } =20 - def->data.spice.streaming =3D modeVal; + def->data.spice.streaming =3D mode; } else if (virXMLNodeNameEqual(cur, "clipboard")) { - int copypasteVal; - g_autofree char *copypaste =3D virXMLPropString(cur, "copy= paste"); - - if (!copypaste) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("spice clipboard missing copypaste")); + if (virXMLPropTristateBool(cur, "copypaste", + VIR_XML_PROP_REQUIRED, + &def->data.spice.copypaste) < 0) return -1; - } - - if ((copypasteVal =3D - virTristateBoolTypeFromString(copypaste)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown copypaste value '%s'"), copy= paste); - return -1; - } - - def->data.spice.copypaste =3D copypasteVal; } else if (virXMLNodeNameEqual(cur, "filetransfer")) { - int enableVal; - g_autofree char *enable =3D virXMLPropString(cur, "enable"= ); - - if (!enable) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("spice filetransfer missing enable")); + if (virXMLPropTristateBool(cur, "enable", + VIR_XML_PROP_REQUIRED, + &def->data.spice.filetransfer) = < 0) return -1; - } - - if ((enableVal =3D - virTristateBoolTypeFromString(enable)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown enable value '%s'"), enable); - return -1; - } - - def->data.spice.filetransfer =3D enableVal; } else if (virXMLNodeNameEqual(cur, "gl")) { - int enableVal; - g_autofree char *enable =3D virXMLPropString(cur, "enable"= ); - g_autofree char *rendernode =3D virXMLPropString(cur, "ren= dernode"); + def->data.spice.rendernode =3D virXMLPropString(cur, "rend= ernode"); =20 - if (!enable) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("spice gl element missing enable")); - return -1; - } - - if ((enableVal =3D - virTristateBoolTypeFromString(enable)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown enable value '%s'"), enable); + if (virXMLPropTristateBool(cur, "enable", + VIR_XML_PROP_REQUIRED, + &def->data.spice.gl) < 0) return -1; - } - - def->data.spice.gl =3D enableVal; - def->data.spice.rendernode =3D g_steal_pointer(&rendernode= ); - } else if (virXMLNodeNameEqual(cur, "mouse")) { - int modeVal; - g_autofree char *mode =3D virXMLPropString(cur, "mode"); - - if (!mode) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("spice mouse missing mode")); + if (virXMLPropEnum(cur, "mode", + virDomainGraphicsSpiceMouseModeTypeFrom= String, + VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NO= NZERO, + &def->data.spice.mousemode) < 0) return -1; - } - - if ((modeVal =3D virDomainGraphicsSpiceMouseModeTypeFromSt= ring(mode)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown mouse mode value '%s'"), - mode); - return -1; - } - - def->data.spice.mousemode =3D modeVal; } } cur =3D cur->next; --=20 2.26.3 From nobody Sat Apr 20 15:40:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1619522010; cv=none; d=zohomail.com; s=zohoarc; b=Pye3gqW7DTkhSJ5OM3wKINsh4qIWszcBWGR2USIQdoZR5veSTngbrwXoGOtLA9YTm65JUkp16iyTcdstHtKMWi0dpcZdj2rwBUFa4q6Ex3pjbPrc55jTQJYB96ovCZTaJzDAKNlV8MUiPTOVFNN5U1UT7Gn0pgGM6fT6S+KEU0w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619522010; 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=TL/ej6BhqIkUrVF1AeWvsmchapt/3QiyJmt8WDmtNsg=; b=kAAMPTpHhZP+EhaYCs0dYcmgPR8s4z36E9h6svJW5QhPO6jiA9IrVNWO4Diuqh+H3VULL/i5g+fnQT3LTpkQmTaaiUQDlOUXenqzZLC/gC62rWI95P30Dc1+7lyiHMQs6ugG35qp9I/uk0ka1DmcuPRzkv2nB0OtGWrnBB16xg0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1619522010801428.23205056936945; Tue, 27 Apr 2021 04:13:30 -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-20-TT57wSK4Oy2ceZmuRnMTqg-1; Tue, 27 Apr 2021 07:13:27 -0400 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 9772D1898297; Tue, 27 Apr 2021 11:13: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 752CD5DF26; Tue, 27 Apr 2021 11:13: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 3C39144A5C; Tue, 27 Apr 2021 11:13:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13RBD6n0009664 for ; Tue, 27 Apr 2021 07:13:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0FC8360CFB; Tue, 27 Apr 2021 11:13:06 +0000 (UTC) Received: from work.redhat.com (ovpn-113-91.ams2.redhat.com [10.36.113.91]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E7F1687FC; Tue, 27 Apr 2021 11:13:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619522009; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=TL/ej6BhqIkUrVF1AeWvsmchapt/3QiyJmt8WDmtNsg=; b=aWLRLqEHkV7eKHX6AQbqD7NQa1Hu1+jSBRPftTICKASUP/KRcPjSPR58Cn0WwbFZWGqLlW GFwRaqS0KUQAwbA6AocR/uCbpjB093VHotl+NOqs8MlzxrAFkPa/h/wBClMcj30MCaQwDZ vB8jC992bTL0sbsYtPGa5k7xBWgUnSc= X-MC-Unique: TT57wSK4Oy2ceZmuRnMTqg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 2/6] virDomainSoundDefParseXML: Use virXMLProp* Date: Tue, 27 Apr 2021 13:12:53 +0200 Message-Id: <20210427111257.157406-3-twiederh@redhat.com> In-Reply-To: <20210427111257.157406-1-twiederh@redhat.com> References: <20210427111257.157406-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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 X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This strictens the parser to disallow negative values (interpreted as `UINT_MAX + value + 1`) for attribute `id`. `id` must be greater than 0 and does not benefit from being referable as e.g. "-7" for host audio backend 4294967289, as this value is distinctly out of range for normal use. Additionally, this patch fixes a use of NULL string with printf's %s modifier if the `model` attribute is absent. Signed-off-by: Tim Wiederhake Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 822426bc4e..59630415a4 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -13173,20 +13173,14 @@ virDomainSoundDefParseXML(virDomainXMLOption *xml= opt, { virDomainSoundDef *def; VIR_XPATH_NODE_AUTORESTORE(ctxt) - g_autofree char *model =3D NULL; - int modelval; xmlNodePtr audioNode; =20 def =3D g_new0(virDomainSoundDef, 1); ctxt->node =3D node; =20 - model =3D virXMLPropString(node, "model"); - if ((modelval =3D virDomainSoundModelTypeFromString(model)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown sound model '%s'"), model); + if (virXMLPropEnum(node, "model", virDomainSoundModelTypeFromString, + VIR_XML_PROP_REQUIRED, &def->model) < 0) goto error; - } - def->model =3D modelval; =20 if (virDomainSoundModelSupportsCodecs(def)) { int ncodecs; @@ -13215,19 +13209,10 @@ virDomainSoundDefParseXML(virDomainXMLOption *xml= opt, =20 audioNode =3D virXPathNode("./audio", ctxt); if (audioNode) { - g_autofree char *tmp =3D NULL; - tmp =3D virXMLPropString(audioNode, "id"); - if (!tmp) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("missing audio 'id' attribute")); - goto error; - } - if (virStrToLong_ui(tmp, NULL, 10, &def->audioId) < 0 || - def->audioId =3D=3D 0) { - virReportError(VIR_ERR_XML_ERROR, - _("Invalid audio 'id' value '%s'"), tmp); + if (virXMLPropUInt(audioNode, "id", 10, + VIR_XML_PROP_REQUIRED | VIR_XML_PROP_NONZERO, + &def->audioId) < 0) goto error; - } } =20 if (virDomainDeviceInfoParseXML(xmlopt, node, ctxt, &def->info, flags)= < 0) --=20 2.26.3 From nobody Sat Apr 20 15:40:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1619522001; cv=none; d=zohomail.com; s=zohoarc; b=fjpSr3D4J/oei7J9K8aWLtRCWg800cU80Iu0HiHMjJ7cxBIOaUeJyo0EaagDmzXBswlT7391UvfiDcWQdWizSMXJSBFvkgHkmeI2J7EgAZCLis3hZRkLim0xug/+4CUYfa0i5eA4YSH5EO1S2i9gvkW06aCMPJpQW9G3qDEyYDg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619522001; 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=JvxMHzEzQ5cinI80RT7rF10up5frTrLf/azGh6/5b58=; b=YH1HY2gQSvy2zVWUQue7JpjfuNKIO8c4yW1wshaAxtJwjSW7K9sHAL6wvss8jYawkMjY2A3+AY4mr5WXX6IIS/ZALsmdqsP8C7ngFrX/vFfAcmfu5U8D1PSGB1GP1nY4Ii8z6Ibq1NqLWRInNDoYQp/rfcPAvTitSQnVhxWy7c0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1619522001438620.5932955447296; Tue, 27 Apr 2021 04:13:21 -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-598-jBa1cFpsPIWMQFXotRT8mw-1; Tue, 27 Apr 2021 07:13:17 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0FE156D4E3; Tue, 27 Apr 2021 11:13:13 +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 DF5975E1A4; Tue, 27 Apr 2021 11:13:12 +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 A287244A5A; Tue, 27 Apr 2021 11:13:12 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13RBD7ni009679 for ; Tue, 27 Apr 2021 07:13:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id C002814106; Tue, 27 Apr 2021 11:13:07 +0000 (UTC) Received: from work.redhat.com (ovpn-113-91.ams2.redhat.com [10.36.113.91]) by smtp.corp.redhat.com (Postfix) with ESMTP id 91DEC687FC; Tue, 27 Apr 2021 11:13:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619522000; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=JvxMHzEzQ5cinI80RT7rF10up5frTrLf/azGh6/5b58=; b=Rl7npBiDRQoBK6YUtQAe0IQ3zpVlSF/YddgU6/wCKcB2EDY0gl4sVdjFK6i9Ub8orAT99b e8saVYPEH+dGUdAwpR3PbXEqU0BMer4BhweG0e2jcbDqso1dvQVz9fMfDBQV0c6eklfiCS FVLnFBxkyld6OX9jFm9oAltXSwLAWh0= X-MC-Unique: jBa1cFpsPIWMQFXotRT8mw-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 3/6] virDomainFeaturesDefParse: Use virXMLPropUInt Date: Tue, 27 Apr 2021 13:12:54 +0200 Message-Id: <20210427111257.157406-4-twiederh@redhat.com> In-Reply-To: <20210427111257.157406-1-twiederh@redhat.com> References: <20210427111257.157406-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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.16 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" This strictens the parser to disallow negative values (interpreted as `UINT_MAX + value + 1`) for attribute `retries`. UINT_MAX holds no special significance for this attribute and is distinctly out of range for normal use. Signed-off-by: Tim Wiederhake Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 59630415a4..b1e5115c7e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -18108,12 +18108,10 @@ virDomainFeaturesDefParse(virDomainDef *def, if (value !=3D VIR_TRISTATE_SWITCH_ON) break; =20 - if (virXPathUInt("string(./@retries)", ctxt, - &def->hyperv_spinlocks) < 0) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("invalid HyperV spinlock retry count"= )); + if (virXMLPropUInt(nodes[i], "retries", 0, + VIR_XML_PROP_REQUIRED, + &def->hyperv_spinlocks) < 0) return -1; - } =20 if (def->hyperv_spinlocks < 0xFFF) { virReportError(VIR_ERR_XML_ERROR, "%s", --=20 2.26.3 From nobody Sat Apr 20 15:40:01 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=1619522011; cv=none; d=zohomail.com; s=zohoarc; b=PqJMeIy1HNPnOisR/h4FaufU0dvzF0wSZb9zOvjK7Jt63nI1btTD7VNraC36GlaZMuiKHHNMpsdyKWJQfllTGnQKrh/HimO2dAN3KVFAoBSHbQ1Oz4vD9TcE7Q95H6+rE8uER33Mr3CieFUnIkD7sslSClUyVcKAiG1QGmxOJaA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619522011; 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=ihxHA3+CqaQhz7yg/W3H6j8QLN6CtDzmd5K5xVg8ArI=; b=SIXY1uRzq6SGxOQ2ccQ0tvJD79ZpDL1Tw3I/cSZIInsc2PyzNZcAPFsqs207u8O2mOZ+CkCkGh1b+BSS12iwAoign59+VJOZ0NLLtEItWJWgU+8rQ1leNwprNLPCui5OnTnoLM9cvhTWR0FRwxHPBjpLArQbgRN0agO7M+itHZU= 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) header.from= 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 1619522011668105.20580809631929; Tue, 27 Apr 2021 04:13:31 -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-33-P5L70P7kOFqZHAoiia4vBg-1; Tue, 27 Apr 2021 07:13:28 -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 6AFF16D4F0; Tue, 27 Apr 2021 11:13:22 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4C8D862AFA; Tue, 27 Apr 2021 11:13: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 1BD651806D1F; Tue, 27 Apr 2021 11:13:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13RBD9bU009690 for ; Tue, 27 Apr 2021 07:13:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5103D6A036; Tue, 27 Apr 2021 11:13:09 +0000 (UTC) Received: from work.redhat.com (ovpn-113-91.ams2.redhat.com [10.36.113.91]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4239760CFB; Tue, 27 Apr 2021 11:13:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619522010; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ihxHA3+CqaQhz7yg/W3H6j8QLN6CtDzmd5K5xVg8ArI=; b=X/5GOmACVOLn95RD3sNjeot/8PAV3GPgdHYVq/i5m5mducq0yjAT+F/eBNlh6lb7YpsjUb 4SabvhLg5IScgglISFM5MYdhlqWntnB1S80v5MFOEHnqqsGqoAQs90ieJkE5vB1pXYpQBu vySq5wZVfbArWPiTWJbtJ907fgioNYs= X-MC-Unique: P5L70P7kOFqZHAoiia4vBg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 4/6] virDomainFeaturesDefParse: Use virXMLPropTristateSwitch Date: Tue, 27 Apr 2021 13:12:55 +0200 Message-Id: <20210427111257.157406-5-twiederh@redhat.com> In-Reply-To: <20210427111257.157406-1-twiederh@redhat.com> References: <20210427111257.157406-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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" Signed-off-by: Tim Wiederhake Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 141 +++++++++++------------------------------ 1 file changed, 37 insertions(+), 104 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index b1e5115c7e..4c7affe5af 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -17913,18 +17913,16 @@ virDomainFeaturesDefParse(virDomainDef *def, case VIR_DOMAIN_FEATURE_PMU: case VIR_DOMAIN_FEATURE_PVSPINLOCK: case VIR_DOMAIN_FEATURE_VMPORT: - case VIR_DOMAIN_FEATURE_SMM: - if ((tmp =3D virXMLPropString(nodes[i], "state"))) { - if ((def->features[val] =3D virTristateSwitchTypeFromStrin= g(tmp)) =3D=3D -1) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown state attribute '%s' of feat= ure '%s'"), - tmp, virDomainFeatureTypeToString(val)); - return -1; - } - } else { - def->features[val] =3D VIR_TRISTATE_SWITCH_ON; - } + case VIR_DOMAIN_FEATURE_SMM: { + virTristateSwitch state =3D VIR_TRISTATE_SWITCH_ON; + + if (virXMLPropTristateSwitch(nodes[i], "state", + VIR_XML_PROP_NONE, &state) < 0) + return -1; + + def->features[val] =3D state; break; + } =20 case VIR_DOMAIN_FEATURE_GIC: if ((tmp =3D virXMLPropString(nodes[i], "version"))) { @@ -18030,20 +18028,16 @@ virDomainFeaturesDefParse(virDomainDef *def, =20 case VIR_DOMAIN_FEATURE_HTM: case VIR_DOMAIN_FEATURE_NESTED_HV: - case VIR_DOMAIN_FEATURE_CCF_ASSIST: - if (!(tmp =3D virXMLPropString(nodes[i], "state"))) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("missing state attribute '%s' of feature = '%s'"), - tmp, virDomainFeatureTypeToString(val)); - return -1; - } - if ((def->features[val] =3D virTristateSwitchTypeFromString(tm= p)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown state attribute '%s' of feature = '%s'"), - tmp, virDomainFeatureTypeToString(val)); + case VIR_DOMAIN_FEATURE_CCF_ASSIST: { + virTristateSwitch state; + + if (virXMLPropTristateSwitch(nodes[i], "state", + VIR_XML_PROP_REQUIRED, &state) < = 0) return -1; - } + + def->features[val] =3D state; break; + } =20 /* coverity[dead_error_begin] */ case VIR_DOMAIN_FEATURE_LAST: @@ -18054,13 +18048,11 @@ virDomainFeaturesDefParse(virDomainDef *def, =20 if (def->features[VIR_DOMAIN_FEATURE_HYPERV] =3D=3D VIR_TRISTATE_SWITC= H_ON) { int feature; - int value; - xmlNodePtr node =3D ctxt->node; + virTristateSwitch value; if ((n =3D virXPathNodeSet("./features/hyperv/*", ctxt, &nodes)) <= 0) return -1; =20 for (i =3D 0; i < n; i++) { - g_autofree char *tmp =3D NULL; feature =3D virDomainHypervTypeFromString((const char *)nodes[= i]->name); if (feature < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -18069,23 +18061,9 @@ virDomainFeaturesDefParse(virDomainDef *def, return -1; } =20 - ctxt->node =3D nodes[i]; - - if (!(tmp =3D virXMLPropString(nodes[i], "state"))) { - virReportError(VIR_ERR_XML_ERROR, - _("missing 'state' attribute for " - "HyperV Enlightenment feature '%s'"), - nodes[i]->name); - return -1; - } - - if ((value =3D virTristateSwitchTypeFromString(tmp)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("invalid value of state argument " - "for HyperV Enlightenment feature '%s'"), - nodes[i]->name); + if (virXMLPropTristateSwitch(nodes[i], "state", + VIR_XML_PROP_REQUIRED, &value) < = 0) return -1; - } =20 def->hyperv_features[feature] =3D value; =20 @@ -18155,17 +18133,13 @@ virDomainFeaturesDefParse(virDomainDef *def, } } VIR_FREE(nodes); - ctxt->node =3D node; } =20 if (def->hyperv_features[VIR_DOMAIN_HYPERV_STIMER] =3D=3D VIR_TRISTATE= _SWITCH_ON) { - int value; if ((n =3D virXPathNodeSet("./features/hyperv/stimer/*", ctxt, &no= des)) < 0) return -1; =20 for (i =3D 0; i < n; i++) { - g_autofree char *tmp =3D NULL; - if (STRNEQ((const char *)nodes[i]->name, "direct")) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unsupported Hyper-V stimer feature: %s"), @@ -18173,34 +18147,21 @@ virDomainFeaturesDefParse(virDomainDef *def, return -1; } =20 - if (!(tmp =3D virXMLPropString(nodes[i], "state"))) { - virReportError(VIR_ERR_XML_ERROR, - _("missing 'state' attribute for " - "Hyper-V stimer '%s' feature"), "direct"); - return -1; - } - - if ((value =3D virTristateSwitchTypeFromString(tmp)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("invalid value of state argument " - "for Hyper-V stimer '%s' feature"), "dire= ct"); + if (virXMLPropTristateSwitch(nodes[i], "state", + VIR_XML_PROP_REQUIRED, + &def->hyperv_stimer_direct) < 0) return -1; - } - - def->hyperv_stimer_direct =3D value; } VIR_FREE(nodes); } =20 if (def->features[VIR_DOMAIN_FEATURE_KVM] =3D=3D VIR_TRISTATE_SWITCH_O= N) { int feature; - int value; + virTristateSwitch value; if ((n =3D virXPathNodeSet("./features/kvm/*", ctxt, &nodes)) < 0) return -1; =20 for (i =3D 0; i < n; i++) { - g_autofree char *tmp =3D NULL; - feature =3D virDomainKVMTypeFromString((const char *)nodes[i]-= >name); if (feature < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -18213,21 +18174,10 @@ virDomainFeaturesDefParse(virDomainDef *def, case VIR_DOMAIN_KVM_HIDDEN: case VIR_DOMAIN_KVM_DEDICATED: case VIR_DOMAIN_KVM_POLLCONTROL: - if (!(tmp =3D virXMLPropString(nodes[i], "state"))) { - virReportError(VIR_ERR_XML_ERROR, - _("missing 'state' attribute for " - "KVM feature '%s'"), - nodes[i]->name); - return -1; - } - - if ((value =3D virTristateSwitchTypeFromString(tmp)) <= 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("invalid value of state argument " - "for KVM feature '%s'"), - nodes[i]->name); + if (virXMLPropTristateSwitch(nodes[i], "state", + VIR_XML_PROP_REQUIRED, + &value) < 0) return -1; - } =20 def->kvm_features[feature] =3D value; break; @@ -18242,14 +18192,13 @@ virDomainFeaturesDefParse(virDomainDef *def, =20 if (def->features[VIR_DOMAIN_FEATURE_XEN] =3D=3D VIR_TRISTATE_SWITCH_O= N) { int feature; - int value; + virTristateSwitch value; g_autofree char *ptval =3D NULL; =20 if ((n =3D virXPathNodeSet("./features/xen/*", ctxt, &nodes)) < 0) return -1; =20 for (i =3D 0; i < n; i++) { - g_autofree char *tmp =3D NULL; feature =3D virDomainXenTypeFromString((const char *)nodes[i]-= >name); if (feature < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -18258,21 +18207,9 @@ virDomainFeaturesDefParse(virDomainDef *def, return -1; } =20 - if (!(tmp =3D virXMLPropString(nodes[i], "state"))) { - virReportError(VIR_ERR_XML_ERROR, - _("missing 'state' attribute for " - "Xen feature '%s'"), - nodes[i]->name); - return -1; - } - - if ((value =3D virTristateSwitchTypeFromString(tmp)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("invalid value of state argument " - "for Xen feature '%s'"), - nodes[i]->name); + if (virXMLPropTristateSwitch(nodes[i], "state", + VIR_XML_PROP_REQUIRED, &value) < = 0) return -1; - } =20 def->xen_features[feature] =3D value; =20 @@ -18351,7 +18288,7 @@ virDomainFeaturesDefParse(virDomainDef *def, return -1; =20 for (i =3D 0; i < n; i++) { - g_autofree char *tmp =3D NULL; + virTristateSwitch state =3D VIR_TRISTATE_SWITCH_ON; int val =3D virDomainProcessCapsFeatureTypeFromString((const char = *)nodes[i]->name); if (val < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -18359,16 +18296,12 @@ virDomainFeaturesDefParse(virDomainDef *def, return -1; } =20 - if ((tmp =3D virXMLPropString(nodes[i], "state"))) { - if ((def->caps_features[val] =3D virTristateSwitchTypeFromStri= ng(tmp)) =3D=3D -1) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown state attribute '%s' of feature = capability '%s'"), - tmp, virDomainProcessCapsFeatureTypeToStrin= g(val)); - return -1; - } - } else { - def->caps_features[val] =3D VIR_TRISTATE_SWITCH_ON; - } + + if (virXMLPropTristateSwitch(nodes[i], "state", VIR_XML_PROP_NONE, + &state) < 0) + return -1; + + def->caps_features[val] =3D state; } VIR_FREE(nodes); return 0; --=20 2.26.3 From nobody Sat Apr 20 15:40:01 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=1619522013; cv=none; d=zohomail.com; s=zohoarc; b=BpzZJL+JgZNkUFTNme0LNwXa8nUhsfPVBXLKZEUlyv/mtn7OlMRhAO44ra0+kfjWt67ybyimYDYi+dRirSOmgqCeS0neQdR7j7CWx+/olV3pagA6a5/pdchABTp9mP2AzMONdJ0reR7Cf6risQ1WHwgCVQi83FTSsMa1Bcc3Xxk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619522013; 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=XnuOqStMGMAstKfY/H37SOIQwJNml4vyYUOwxBXKLJs=; b=WWbjaFO3q7O12goDDeSLPB5l8BeP/NdGV+KVxjas0WBDxPAT3uULIUBKJ7y6UxOHaBpT8etsTRiB7/swIozEnnoP3q5ONvujLAw+J6qkCpvb4wDwxnc+IbhygiwOiFLHdYS7W+3cP5uXAMcq16SLJ6xsfDtJx7qGs6dwG07FySU= 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) header.from= 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 1619522013607655.4311215561794; Tue, 27 Apr 2021 04:13:33 -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-175-hoQqFiNBMMSN2oQpqtZ8SQ-1; Tue, 27 Apr 2021 07:13:29 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B2EC66D4F1; Tue, 27 Apr 2021 11:13:22 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 693F872387; Tue, 27 Apr 2021 11:13: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 3BB811806D20; Tue, 27 Apr 2021 11:13:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13RBDAAW009701 for ; Tue, 27 Apr 2021 07:13:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id C7B6D60CFB; Tue, 27 Apr 2021 11:13:10 +0000 (UTC) Received: from work.redhat.com (ovpn-113-91.ams2.redhat.com [10.36.113.91]) by smtp.corp.redhat.com (Postfix) with ESMTP id CEF43687FF; Tue, 27 Apr 2021 11:13:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619522012; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=XnuOqStMGMAstKfY/H37SOIQwJNml4vyYUOwxBXKLJs=; b=dQNJig6NRow1PHOzbm4sUgVyCDTmWBcO7wGrVNNeuJoiOiCKWgKF6zbAJlbCrdQTw0SoX5 +DHiRN2jFB9FfVi8TAmeNj5dXwN8701tZ20fPtv0+Z+B2sB7bm/FBO7JtH8NVaSLhSVcOB 7eL+ggOeCRPvXVw3ZX8YeD1tx8I+/ok= X-MC-Unique: hoQqFiNBMMSN2oQpqtZ8SQ-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 5/6] virDomainFeaturesDefParse: Use virXMLPropEnum Date: Tue, 27 Apr 2021 13:12:56 +0200 Message-Id: <20210427111257.157406-6-twiederh@redhat.com> In-Reply-To: <20210427111257.157406-1-twiederh@redhat.com> References: <20210427111257.157406-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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.84 on 10.5.11.23 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" Signed-off-by: Tim Wiederhake Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 174 +++++++----------- .../qemuxml2argvdata/aarch64-gic-invalid.err | 2 +- 2 files changed, 64 insertions(+), 112 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4c7affe5af..145b898adb 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -17895,18 +17895,17 @@ virDomainFeaturesDefParse(virDomainDef *def, def->features[val] =3D VIR_TRISTATE_SWITCH_ON; break; =20 - case VIR_DOMAIN_FEATURE_CAPABILITIES: - if ((tmp =3D virXMLPropString(nodes[i], "policy"))) { - if ((def->features[val] =3D virDomainCapabilitiesPolicyTyp= eFromString(tmp)) =3D=3D -1) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown policy attribute '%s' of fea= ture '%s'"), - tmp, virDomainFeatureTypeToString(val)); - return -1; - } - } else { - def->features[val] =3D VIR_TRISTATE_SWITCH_ABSENT; - } + case VIR_DOMAIN_FEATURE_CAPABILITIES: { + virDomainCapabilitiesPolicy policy =3D VIR_DOMAIN_CAPABILITIES= _POLICY_DEFAULT; + + if (virXMLPropEnum(nodes[i], "policy", + virDomainCapabilitiesPolicyTypeFromString, + VIR_XML_PROP_NONE, &policy) < 0) + return -1; + + def->features[val] =3D policy; break; + } =20 case VIR_DOMAIN_FEATURE_VMCOREINFO: case VIR_DOMAIN_FEATURE_HAP: @@ -17925,44 +17924,29 @@ virDomainFeaturesDefParse(virDomainDef *def, } =20 case VIR_DOMAIN_FEATURE_GIC: - if ((tmp =3D virXMLPropString(nodes[i], "version"))) { - int gic_version =3D virGICVersionTypeFromString(tmp); - if (gic_version < 0 || gic_version =3D=3D VIR_GIC_VERSION_= NONE) { - virReportError(VIR_ERR_XML_ERROR, - _("malformed gic version: %s"), tmp); - return -1; - } - def->gic_version =3D gic_version; - } + if (virXMLPropEnum(nodes[i], "version", virGICVersionTypeFromS= tring, + VIR_XML_PROP_NONZERO, &def->gic_version) < = 0) + return -1; + def->features[val] =3D VIR_TRISTATE_SWITCH_ON; break; =20 - case VIR_DOMAIN_FEATURE_IOAPIC: - tmp =3D virXMLPropString(nodes[i], "driver"); - if (tmp) { - int value =3D virDomainIOAPICTypeFromString(tmp); - if (value < 0 || value =3D=3D VIR_DOMAIN_IOAPIC_NONE) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown driver mode: %s"), - tmp); - return -1; - } - def->features[val] =3D value; - } + case VIR_DOMAIN_FEATURE_IOAPIC: { + virDomainIOAPIC driver =3D VIR_DOMAIN_IOAPIC_NONE; + + if (virXMLPropEnum(nodes[i], "driver", virDomainIOAPICTypeFrom= String, + VIR_XML_PROP_NONZERO, &driver) < 0) + return -1; + + def->features[val] =3D driver; break; + } =20 case VIR_DOMAIN_FEATURE_HPT: - tmp =3D virXMLPropString(nodes[i], "resizing"); - if (tmp) { - int value =3D virDomainHPTResizingTypeFromString(tmp); - if (value < 0 || value =3D=3D VIR_DOMAIN_HPT_RESIZING_NONE= ) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown HPT resizing setting: %s"), - tmp); - return -1; - } - def->hpt_resizing =3D (virDomainHPTResizing) value; - } + if (virXMLPropEnum(nodes[i], "resizing", + virDomainHPTResizingTypeFromString, + VIR_XML_PROP_NONZERO, &def->hpt_resizing) <= 0) + return -1; =20 if (virParseScaledValue("./features/hpt/maxpagesize", NULL, @@ -17984,47 +17968,38 @@ virDomainFeaturesDefParse(virDomainDef *def, } break; =20 - case VIR_DOMAIN_FEATURE_CFPC: - tmp =3D virXMLPropString(nodes[i], "value"); - if (tmp) { - int value =3D virDomainCFPCTypeFromString(tmp); - if (value < 0 || value =3D=3D VIR_DOMAIN_CFPC_NONE) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown value: %s"), - tmp); - return -1; - } - def->features[val] =3D value; - } + case VIR_DOMAIN_FEATURE_CFPC: { + virDomainCFPC value =3D VIR_DOMAIN_CFPC_NONE; + + if (virXMLPropEnum(nodes[i], "value", virDomainCFPCTypeFromStr= ing, + VIR_XML_PROP_NONZERO, &value) < 0) + return -1; + + def->features[val] =3D value; break; + } =20 - case VIR_DOMAIN_FEATURE_SBBC: - tmp =3D virXMLPropString(nodes[i], "value"); - if (tmp) { - int value =3D virDomainSBBCTypeFromString(tmp); - if (value < 0 || value =3D=3D VIR_DOMAIN_SBBC_NONE) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown value: %s"), - tmp); - return -1; - } - def->features[val] =3D value; - } + case VIR_DOMAIN_FEATURE_SBBC: { + virDomainSBBC value =3D VIR_DOMAIN_SBBC_NONE; + + if (virXMLPropEnum(nodes[i], "value", virDomainSBBCTypeFromStr= ing, + VIR_XML_PROP_NONZERO, &value) < 0) + return -1; + + def->features[val] =3D value; break; + } =20 - case VIR_DOMAIN_FEATURE_IBS: - tmp =3D virXMLPropString(nodes[i], "value"); - if (tmp) { - int value =3D virDomainIBSTypeFromString(tmp); - if (value < 0 || value =3D=3D VIR_DOMAIN_IBS_NONE) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("Unknown value: %s"), - tmp); - return -1; - } - def->features[val] =3D value; - } + case VIR_DOMAIN_FEATURE_IBS: { + virDomainIBS value =3D VIR_DOMAIN_IBS_NONE; + + if (virXMLPropEnum(nodes[i], "value", virDomainIBSTypeFromStri= ng, + VIR_XML_PROP_NONZERO, &value) < 0) + return -1; + + def->features[val] =3D value; break; + } =20 case VIR_DOMAIN_FEATURE_HTM: case VIR_DOMAIN_FEATURE_NESTED_HV: @@ -18193,7 +18168,6 @@ virDomainFeaturesDefParse(virDomainDef *def, if (def->features[VIR_DOMAIN_FEATURE_XEN] =3D=3D VIR_TRISTATE_SWITCH_O= N) { int feature; virTristateSwitch value; - g_autofree char *ptval =3D NULL; =20 if ((n =3D virXPathNodeSet("./features/xen/*", ctxt, &nodes)) < 0) return -1; @@ -18221,25 +18195,11 @@ virDomainFeaturesDefParse(virDomainDef *def, if (value !=3D VIR_TRISTATE_SWITCH_ON) break; =20 - if ((ptval =3D virXMLPropString(nodes[i], "mode"))) { - int mode =3D virDomainXenPassthroughModeTypeFromString= (ptval); - - if (mode < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unsupported mode '%s' for Xen pa= ssthrough feature"), - ptval); - return -1; - } - - if (mode !=3D VIR_DOMAIN_XEN_PASSTHROUGH_MODE_SYNC_PT = && - mode !=3D VIR_DOMAIN_XEN_PASSTHROUGH_MODE_SHARE_PT= ) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("'mode' attribute for Xen feature= " - "'passthrough' must be 'sync_pt' = or 'share_pt'")); - return -1; - } - def->xen_passthrough_mode =3D mode; - } + if (virXMLPropEnum(nodes[i], "mode", + virDomainXenPassthroughModeTypeFromStri= ng, + VIR_XML_PROP_NONZERO, + &def->xen_passthrough_mode) < 0) + return -1; break; =20 /* coverity[dead_error_begin] */ @@ -18264,24 +18224,16 @@ virDomainFeaturesDefParse(virDomainDef *def, } =20 if (def->features[VIR_DOMAIN_FEATURE_MSRS] =3D=3D VIR_TRISTATE_SWITCH_= ON) { - g_autofree char *tmp =3D NULL; + virDomainMsrsUnknown unknown; xmlNodePtr node =3D NULL; if ((node =3D virXPathNode("./features/msrs", ctxt)) =3D=3D NULL) return -1; =20 - if (!(tmp =3D virXMLPropString(node, "unknown"))) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("missing 'unknown' attribute for feature '%s'= "), - virDomainFeatureTypeToString(VIR_DOMAIN_FEATURE= _MSRS)); + if (virXMLPropEnum(node, "unknown", virDomainMsrsUnknownTypeFromSt= ring, + VIR_XML_PROP_REQUIRED, &unknown) < 0) return -1; - } =20 - if ((def->msrs_features[VIR_DOMAIN_MSRS_UNKNOWN] =3D virDomainMsrs= UnknownTypeFromString(tmp)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown 'unknown' value '%s'"), - tmp); - return -1; - } + def->msrs_features[VIR_DOMAIN_MSRS_UNKNOWN] =3D unknown; } =20 if ((n =3D virXPathNodeSet("./features/capabilities/*", ctxt, &nodes))= < 0) diff --git a/tests/qemuxml2argvdata/aarch64-gic-invalid.err b/tests/qemuxml= 2argvdata/aarch64-gic-invalid.err index c2e9f4aa3f..18de19f660 100644 --- a/tests/qemuxml2argvdata/aarch64-gic-invalid.err +++ b/tests/qemuxml2argvdata/aarch64-gic-invalid.err @@ -1 +1 @@ -XML error: malformed gic version: none +XML error: Invalid value for attribute 'version' in element 'gic': 'none'. --=20 2.26.3 From nobody Sat Apr 20 15:40:01 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1619522014; cv=none; d=zohomail.com; s=zohoarc; b=jK8nDeIsz8+w7wk8/HHTt1+WDvBivy5Jr1k3GVbuTss2mh3gVqYbcY678i9wBJ6d2kUiAplcowOHt/KzL90OeARgiLS3gyr7KnOm1R2ZF1VbW8fIWCTlX6yFKAOJqDEMrU7H47hIqmxH/xKoxpiE2TChWUDBQJQHWenUGsRpw2g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619522014; 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=bl4d5F0/OYYn+W2wgqCwgLbUSOF0eahyS2RksRIIdjE=; b=NMTfbiXsqASbjKyyjPwEADu+vBg6O6OzCBc8rHEtbvWnZ5dU6fr27b9xKavJo2n/3EZGzaWVuurKjf1fNpngs5VpQMLjn0OitjbP1IN+pwsdqGcwBJFCrJJDwMqcBv6XON355+TuTcd2EfixVYpEelANCCC/i/SsX3tnmS/n8dM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1619522014459388.09378500629384; Tue, 27 Apr 2021 04:13:34 -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-206-310hkPiMMWidg3Z78pam2Q-1; Tue, 27 Apr 2021 07:13:30 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1601D81840B; Tue, 27 Apr 2021 11:13:26 +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 B01976910A; Tue, 27 Apr 2021 11:13:25 +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 7920D44A5C; Tue, 27 Apr 2021 11:13:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13RBDCxp009709 for ; Tue, 27 Apr 2021 07:13:12 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8E9AF6A045; Tue, 27 Apr 2021 11:13:12 +0000 (UTC) Received: from work.redhat.com (ovpn-113-91.ams2.redhat.com [10.36.113.91]) by smtp.corp.redhat.com (Postfix) with ESMTP id 61AE060CFB; Tue, 27 Apr 2021 11:13:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619522013; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=bl4d5F0/OYYn+W2wgqCwgLbUSOF0eahyS2RksRIIdjE=; b=hpX25QwJMQhwPfgww5vP1oJBHdYYk6LQx/RHB8DFjsUWpcvhUguApW1ZTWhSi9K064PLgo cULfU50Ux10mRwtFRp7yuFYlUyfl/98dZxXvyb5hl5dAO/Y0ZBtKTmwD+W/ITHAh4pKquZ G49K9SNlug/UaNfrmaNE1Cdg0MxBczE= X-MC-Unique: 310hkPiMMWidg3Z78pam2Q-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH v2 6/6] virDomainAudioSDLParse: Use virXMLProp* Date: Tue, 27 Apr 2021 13:12:57 +0200 Message-Id: <20210427111257.157406-7-twiederh@redhat.com> In-Reply-To: <20210427111257.157406-1-twiederh@redhat.com> References: <20210427111257.157406-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Tim Wiederhake 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.11 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" This strictens the parser to disallow negative values (interpreted as `UINT_MAX + value + 1`) for attribute `bufferCount`. `bufferCount` does not benefit from being referable as e.g. "-7" for requesting 4294967289 buffers, as this value is distinctly out of range for normal use. Signed-off-by: Tim Wiederhake Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 145b898adb..66217289d1 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -13455,15 +13455,9 @@ static int virDomainAudioSDLParse(virDomainAudioIOSDL *def, xmlNodePtr node) { - g_autofree char *bufferCount =3D virXMLPropString(node, "bufferCount"); - - if (bufferCount && - virStrToLong_ui(bufferCount, NULL, 10, - &def->bufferCount) < 0) { - virReportError(VIR_ERR_XML_ERROR, - _("cannot parse 'bufferCount' value '%s'"), bufferC= ount); + if (virXMLPropUInt(node, "bufferCount", 10, VIR_XML_PROP_NONE, + &def->bufferCount) < 0) return -1; - } =20 return 0; } --=20 2.26.3