From nobody Tue Feb 10 12:57:47 2026 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=1619535917; cv=none; d=zohomail.com; s=zohoarc; b=DnMnU4nmZ1Qv7gO6KNJ59jWVNMt3XCDQpgqcEBYWGh8B6bEd7Q0Or6BDwFvrBTsBnCY8nnBRxq99ul0tl+msWOv8uGZHiovtvWbxc/YWK2CVlo2c37DwYSO5K6e2uqqA6YZ+yZmGsuPRhCL3nHXeKODEHCSzsVpYy6fKbJju8G0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619535917; 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=ps69jDyXzb2fkKNxw2U5m6lYU/0uljKwPF4R2ZczDm4=; b=l1nWtQGlD9f564pkUB6Lt4shSy5EnbZWeNy8CkGs9+RsasFPGdyc76fVz9hjVQEMmXV8/qT55jCKMBeaWo451mr527xAvXFj4M33KEgE6pZ754pL0xvBC8LlVyfPfH8riD7f/DSZrXqqzt+T3Kd7ra/TJaYlkBoDi9fnLhpkqYk= 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 1619535917174736.7663748553969; Tue, 27 Apr 2021 08:05:17 -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-593-RdqMabWmM4iWNQf6f_M7kg-1; Tue, 27 Apr 2021 11:05:12 -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 74D3218B9ECB; Tue, 27 Apr 2021 15:05:06 +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 3E1791A865; Tue, 27 Apr 2021 15:05:06 +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 BF59344A60; Tue, 27 Apr 2021 15:05:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13RF4mjY031859 for ; Tue, 27 Apr 2021 11:04:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id EE03A60CC6; Tue, 27 Apr 2021 15:04:48 +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 42E9D60C0F; Tue, 27 Apr 2021 15:04:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1619535915; 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=ps69jDyXzb2fkKNxw2U5m6lYU/0uljKwPF4R2ZczDm4=; b=BhKtDr0GxVBeXUzEnywNS8cPaF28OgYwdv9SXa9dh88me/EZMYdXoMdEX1zmfig3LadBB5 nQIvN1b9l30oixV3uyEdJjlrWWkLagq+JfFpkbXtI+AMVPJdzvptRnL3z8y3bHGXLwALPL svNgdrmr3u+VGe2zk08dvJ6ksrZmIsM= X-MC-Unique: RdqMabWmM4iWNQf6f_M7kg-1 From: Tim Wiederhake To: libvir-list@redhat.com Subject: [libvirt PATCH 02/10] virDomainAudioCommonParse: Use virXMLProp* Date: Tue, 27 Apr 2021 17:04:33 +0200 Message-Id: <20210427150441.206606-3-twiederh@redhat.com> In-Reply-To: <20210427150441.206606-1-twiederh@redhat.com> References: <20210427150441.206606-1-twiederh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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" This strictens the parser to disallow negative values (interpreted as `UINT_MAX + value + 1`) for attributes `voices` (typically 1), `bufferLength` (measured in milliseconds), `frequency` (in Hz, typically 44100), and `channels` (typically 2 for stereo). None of these properties benefit from or have a sensible use-case for wrap-around behavior. Signed-off-by: Tim Wiederhake Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 73 ++++++++++++------------------------------ 1 file changed, 20 insertions(+), 53 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index d8e34e79b0..371a9dead7 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -13419,31 +13419,19 @@ virDomainAudioCommonParse(virDomainAudioIOCommon = *def, xmlNodePtr node, xmlXPathContextPtr ctxt) { - g_autofree char *mixingEngine =3D virXMLPropString(node, "mixingEngine= "); - g_autofree char *fixedSettings =3D virXMLPropString(node, "fixedSettin= gs"); - g_autofree char *voices =3D virXMLPropString(node, "voices"); - g_autofree char *bufferLength =3D virXMLPropString(node, "bufferLength= "); xmlNodePtr settings; VIR_XPATH_NODE_AUTORESTORE(ctxt); =20 ctxt->node =3D node; settings =3D virXPathNode("./settings", ctxt); =20 - if (mixingEngine && - ((def->mixingEngine =3D - virTristateBoolTypeFromString(mixingEngine)) <=3D 0)) { - virReportError(VIR_ERR_XML_ERROR, - _("unknown 'mixingEngine' value '%s'"), mixingEngin= e); + if (virXMLPropTristateBool(node, "mixingEngine", VIR_XML_PROP_NONE, + &def->mixingEngine) < 0) return -1; - } =20 - if (fixedSettings && - ((def->fixedSettings =3D - virTristateBoolTypeFromString(fixedSettings)) <=3D 0)) { - virReportError(VIR_ERR_XML_ERROR, - _("unknown 'fixedSettings' value '%s'"), fixedSetti= ngs); + if (virXMLPropTristateBool(node, "fixedSettings", VIR_XML_PROP_NONE, + &def->fixedSettings) < 0) return -1; - } =20 if (def->fixedSettings =3D=3D VIR_TRISTATE_BOOL_YES && def->mixingEngine !=3D VIR_TRISTATE_BOOL_YES) { @@ -13452,58 +13440,37 @@ virDomainAudioCommonParse(virDomainAudioIOCommon = *def, return -1; } =20 - if (voices && - (virStrToLong_ui(voices, NULL, 10, &def->voices) < 0 || - !def->voices)) { - virReportError(VIR_ERR_XML_ERROR, - _("cannot parse 'voices' value '%s'"), voices); + if (virXMLPropUInt(node, "voices", 10, + VIR_XML_PROP_NONE | VIR_XML_PROP_NONZERO, + &def->voices) < 0) return -1; - } =20 - if (bufferLength && - (virStrToLong_ui(bufferLength, NULL, 10, &def->bufferLength) < 0 || - !def->bufferLength)) { - virReportError(VIR_ERR_XML_ERROR, - _("cannot parse 'bufferLength' value '%s'"), buffer= Length); + if (virXMLPropUInt(node, "bufferLength", 10, + VIR_XML_PROP_NONE | VIR_XML_PROP_NONZERO, + &def->bufferLength) < 0) return -1; - } =20 if (settings) { - g_autofree char *frequency =3D virXMLPropString(settings, "frequen= cy"); - g_autofree char *channels =3D virXMLPropString(settings, "channels= "); - g_autofree char *format =3D virXMLPropString(settings, "format"); - if (def->fixedSettings !=3D VIR_TRISTATE_BOOL_YES) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("audio settings specified without fixed setti= ngs flag")); return -1; } =20 - if (frequency && - (virStrToLong_ui(frequency, NULL, 10, &def->frequency) < 0 || - !def->frequency)) { - virReportError(VIR_ERR_XML_ERROR, - _("cannot parse 'frequency' value '%s'"), frequ= ency); + if (virXMLPropUInt(settings, "frequency", 10, + VIR_XML_PROP_NONE | VIR_XML_PROP_NONZERO, + &def->frequency) < 0) return -1; - } =20 - if (channels && - (virStrToLong_ui(channels, NULL, 10, &def->channels) < 0 || - !def->channels)) { - virReportError(VIR_ERR_XML_ERROR, - _("cannot parse 'channels' value '%s'"), channe= ls); + if (virXMLPropUInt(settings, "channels", 10, + VIR_XML_PROP_NONE | VIR_XML_PROP_NONZERO, + &def->channels) < 0) return -1; - } =20 - if (format) { - int value; - if ((value =3D virDomainAudioFormatTypeFromString(format)) <= =3D 0) { - virReportError(VIR_ERR_XML_ERROR, - _("cannot parse 'format' value '%s'"), form= at); - return -1; - } - def->format =3D value; - } + if (virXMLPropEnum(settings, "format", + virDomainAudioFormatTypeFromString, + VIR_XML_PROP_NONE, &def->format) < 0) + return -1; } =20 return 0; --=20 2.26.3