From nobody Sat Feb 7 07:10:32 2026 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=1621433941; cv=none; d=zohomail.com; s=zohoarc; b=RV7OI+DrDN4z+S6ex6fVzmk7I7CmR09KbvX0msezlPGwcPXNxOePdM330URKt0R7KkaVZIwJOlHew5WuXWXltZ/p+2jdrocLmekYtUnKtThIXIQw3w/ly/Tk0jVtzXo8ErSVGZIGUfuWNh6vr6UQj0oSBuUDb9hBn9+mqMry5Ic= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621433941; 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=8p7Sz3887/VQWypX79HmTKpouSBCIpStlYqIehLxxFc=; b=SR+a++NVmOt/ZaOnuzODpFm6Oa/yD6ylpTVAh4AMUxpe96oAdWk97jfwznX37rUIQs/Sz+sSPnCzohWg8Hf+nfLJRk/N3CBLocZCAv7R/Hl015rw0jsItPF3pXNlgxcyh13E9PtXi1DVxf9EuKEhmFrI/spwmLYo0SV4mC6glD0= 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 162143394113249.24214981309217; Wed, 19 May 2021 07:19:01 -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-126-tR3k42yiN_OZX-4YxqYlfA-1; Wed, 19 May 2021 10:18:56 -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 E723588BB2A; Wed, 19 May 2021 14:18:50 +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 C30235C1D0; Wed, 19 May 2021 14:18:50 +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 91C951800FFC; Wed, 19 May 2021 14:18:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 14JEALhp011850 for ; Wed, 19 May 2021 10:10:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 46FD51037EB3; Wed, 19 May 2021 14:10:21 +0000 (UTC) Received: from work.redhat.com (ovpn-113-53.ams2.redhat.com [10.36.113.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8947210013C1; Wed, 19 May 2021 14:10:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621433938; 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=8p7Sz3887/VQWypX79HmTKpouSBCIpStlYqIehLxxFc=; b=SwqJz2xPAGPFeBV9YR7ZnWodeZKhY/3gNIYHLNg3ga6826w8jnnlL0tufzv8uFCvQLB6cK EKpa+nw0PC1eZDWMWlm6U88WBzEjnytVzGxvz0PAomwYJEkgOPZPvnrDLIyupSMxmYOb/p pw994ECMJ+Ww6/YARWGEC1q3wzA68/g= X-MC-Unique: tR3k42yiN_OZX-4YxqYlfA-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 04/10] virDomainAudioDefParseXML: Use virXMLProp* Date: Wed, 19 May 2021 16:10:06 +0200 Message-Id: <20210519141012.125114-5-twiederh@redhat.com> In-Reply-To: <20210519141012.125114-1-twiederh@redhat.com> References: <20210519141012.125114-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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 `id`. Allowing negative numbers to be interpreted this way makes no sense for this attribute. Signed-off-by: Tim Wiederhake --- src/conf/domain_conf.c | 74 ++++++++++++------------------------------ 1 file changed, 21 insertions(+), 53 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 9e6719265f..2142e45fd5 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -13122,40 +13122,18 @@ virDomainAudioDefParseXML(virDomainXMLOption *xml= opt G_GNUC_UNUSED, { virDomainAudioDef *def; VIR_XPATH_NODE_AUTORESTORE(ctxt) - g_autofree char *tmp =3D NULL; - g_autofree char *typestr =3D NULL; - int type; xmlNodePtr inputNode, outputNode; =20 def =3D g_new0(virDomainAudioDef, 1); ctxt->node =3D node; =20 - typestr =3D virXMLPropString(node, "type"); - if (!typestr) { - virReportError(VIR_ERR_XML_ERROR, "%s", - _("missing audio 'type' attribute")); - goto error; - } - - if ((type =3D virDomainAudioTypeTypeFromString(typestr)) < 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown audio type '%s'"), typestr); + if (virXMLPropEnum(node, "type", virDomainAudioTypeTypeFromString, + VIR_XML_PROP_REQUIRED, &def->type) < 0) goto error; - } - def->type =3D type; =20 - tmp =3D virXMLPropString(node, "id"); - if (!tmp) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("missing audio 'id' attribute")); - goto error; - } - if (virStrToLong_ui(tmp, NULL, 10, &def->id) < 0 || - def->id =3D=3D 0) { - virReportError(VIR_ERR_XML_ERROR, - _("invalid audio 'id' value '%s'"), tmp); + if (virXMLPropUInt(node, "id", 10, VIR_XML_PROP_REQUIRED | VIR_XML_PRO= P_NONZERO, + &def->id) < 0) goto error; - } =20 inputNode =3D virXPathNode("./input", ctxt); outputNode =3D virXPathNode("./output", ctxt); @@ -13191,29 +13169,25 @@ virDomainAudioDefParseXML(virDomainXMLOption *xml= opt G_GNUC_UNUSED, break; =20 case VIR_DOMAIN_AUDIO_TYPE_OSS: { - g_autofree char *tryMMap =3D virXMLPropString(node, "tryMMap"); - g_autofree char *exclusive =3D virXMLPropString(node, "exclusive"); - g_autofree char *dspPolicy =3D virXMLPropString(node, "dspPolicy"); + int dspPolicySet; =20 - if (tryMMap && ((def->backend.oss.tryMMap =3D - virTristateBoolTypeFromString(tryMMap)) <=3D 0)) { - virReportError(VIR_ERR_XML_ERROR, - _("unknown 'tryMMap' value '%s'"), tryMMap); + if (virXMLPropTristateBool(node, "tryMMap", VIR_XML_PROP_NONE, + &def->backend.oss.tryMMap) < 0) goto error; - } =20 - if (exclusive && ((def->backend.oss.exclusive =3D - virTristateBoolTypeFromString(exclusive)) <=3D = 0)) { - virReportError(VIR_ERR_XML_ERROR, - _("unknown 'exclusive' value '%s'"), exclusive); + if (virXMLPropTristateBool(node, "exclusive", VIR_XML_PROP_NONE, + &def->backend.oss.exclusive) < 0) + goto error; + + if ((dspPolicySet =3D virXMLPropInt(node, "dspPolicy", 10, VIR_XML= _PROP_NONE, + &def->backend.oss.dspPolicy, 0)) < 0) goto error; - } =20 - if (dspPolicy) { - if (virStrToLong_i(dspPolicy, NULL, 10, - &def->backend.oss.dspPolicy) < 0) { + if (dspPolicySet !=3D 0) { + if (def->backend.oss.dspPolicy < 0) { virReportError(VIR_ERR_XML_ERROR, - _("cannot parse 'dspPolicy' value '%s'"), d= spPolicy); + _("cannot parse 'dspPolicy' value '%i'"), + def->backend.oss.dspPolicy); goto error; } def->backend.oss.dspPolicySet =3D true; @@ -13236,16 +13210,10 @@ virDomainAudioDefParseXML(virDomainXMLOption *xml= opt G_GNUC_UNUSED, break; =20 case VIR_DOMAIN_AUDIO_TYPE_SDL: { - g_autofree char *driverstr =3D virXMLPropString(node, "driver"); - int driver; - if (driverstr) { - if ((driver =3D virDomainAudioSDLDriverTypeFromString(driverst= r)) <=3D 0) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unknown SDL driver '%s'"), driverstr); - goto error; - } - def->backend.sdl.driver =3D driver; - } + if (virXMLPropEnum(node, "driver", virDomainAudioSDLDriverTypeFrom= String, + VIR_XML_PROP_NONZERO, &def->backend.sdl.driver)= < 0) + goto error; + if (inputNode) virDomainAudioSDLParse(&def->backend.sdl.input, inputNode); if (outputNode) --=20 2.26.3