From nobody Mon Feb 9 16:02:31 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=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