From nobody Tue Nov 26 15:19:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 205.139.110.61 as permitted sender) client-ip=205.139.110.61; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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=1571852829; cv=none; d=zoho.com; s=zohoarc; b=YEu62poaH50YzSg2lbwp4PhswMbI/3vhzwjHhkLMyBy+ok4TgpjEjkFQeiRHYGFP6cDMCN4iuHf/n3pNZG+NNjKGpvMStjwlXZP/uLEcN7YXzXd3bmN7T+6Fn9YYIeQvZo4ezkpbHPBqIYYBll2iBwI7K4XjpsLZQ0ZUpSHseHM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571852829; 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=3SfG+KFYHXb31FOhQXWBFz7iPmSZy54Zq0hJATgya/M=; b=DXaJavpKHORiGuEAj4bhwdvARQaZcpxaxZWkfXN1HH9zf5NPgu6ImRIXid9giPC3YrOZxaaf+Dd+CFr7+MfikKRjHD2Sb5DzL9TECAF/4iMGg1hMjmCYCPV0gUdDAx5Wh0wVTnRKnO4Ggy0oHwPcs5BTK/B+Okz2RBVVVc2Py6w= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass; spf=pass (zoho.com: domain of redhat.com designates 205.139.110.61 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-1.mimecast.com (us-smtp-1.mimecast.com [205.139.110.61]) by mx.zohomail.com with SMTPS id 1571852829012182.46538805421062; Wed, 23 Oct 2019 10:47:09 -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-116-S7ILq9P7NKe6-WR51Xyozw-1; Wed, 23 Oct 2019 13:47:05 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AE65B47B; Wed, 23 Oct 2019 17:47:00 +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 873C110018FF; Wed, 23 Oct 2019 17:47:00 +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 026D31803B4B; Wed, 23 Oct 2019 17:46:58 +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 x9NHkswK008841 for ; Wed, 23 Oct 2019 13:46:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id E4A5F60624; Wed, 23 Oct 2019 17:46:54 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-117-228.phx2.redhat.com [10.3.117.228]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9CB116061E; Wed, 23 Oct 2019 17:46:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1571852827; 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=3SfG+KFYHXb31FOhQXWBFz7iPmSZy54Zq0hJATgya/M=; b=H1oL8M+ZOsUUw4UjUdcAecaLUtJWOFQxhypXpMCmTjxZ+F8f+IEV5EOWZmzH1TSf3n0jaq C82oHb3agEznglSfYRQJC6lQl6RYZOLPemVL++etLLzoKP73WX4cxoXTEGJkmVSMHxvuKd UMpskBCuEkCaXWPZGYCUlgluT0p1BPg= From: Jonathon Jongsma To: libvir-list@redhat.com Date: Wed, 23 Oct 2019 12:46:48 -0500 Message-Id: <20191023174649.28887-5-jjongsma@redhat.com> In-Reply-To: <20191023174649.28887-1-jjongsma@redhat.com> References: <20191023174649.28887-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: jtomko@redhat.com, crobinso@redhat.com Subject: [libvirt] [PATCH v2 4/5] conf: report errors when parsing video resolution 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.22 X-MC-Unique: S7ILq9P7NKe6-WR51Xyozw-1 X-Mimecast-Spam-Score: 0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" The current code doesn't properly handle errors when parsing a video device's resolution. This patch changes the parse function signature to return an error when we're missing an 'x' or 'y' parameter or when the 'x' or 'y' parameters are not positive integers. No error is returned when no 'resolution' element is found. Previously we were returning a NULL structure for the case where 'x' or 'y' were missing, but were returning an under-specified structure for the other error cases. Signed-off-by: Jonathon Jongsma --- src/conf/domain_conf.c | 44 ++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 269a6ec2c3..b3f32d0b63 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -15338,45 +15338,57 @@ virDomainVideoAccelDefParseXML(xmlNodePtr node) return g_steal_pointer(&def); } =20 -static virDomainVideoResolutionDefPtr -virDomainVideoResolutionDefParseXML(xmlNodePtr node) +static int +virDomainVideoResolutionDefParseXML(xmlNodePtr node, + virDomainVideoResolutionDefPtr *res) { xmlNodePtr cur; g_autofree virDomainVideoResolutionDefPtr def =3D NULL; g_autofree char *x =3D NULL; g_autofree char *y =3D NULL; =20 + *res =3D NULL; cur =3D node->children; while (cur !=3D NULL) { - if (cur->type =3D=3D XML_ELEMENT_NODE) { - if (!x && !y && - virXMLNodeNameEqual(cur, "resolution")) { - x =3D virXMLPropString(cur, "x"); - y =3D virXMLPropString(cur, "y"); - } + if ((cur->type =3D=3D XML_ELEMENT_NODE) && + virXMLNodeNameEqual(cur, "resolution")) { + x =3D virXMLPropString(cur, "x"); + y =3D virXMLPropString(cur, "y"); + break; } cur =3D cur->next; } =20 + /* resolution not specified */ + if (cur =3D=3D NULL) + return 0; + + /* resolution specified, but x or y is missing. report error */ if (!x || !y) - return NULL; + return -1; =20 def =3D g_new0(virDomainVideoResolutionDef, 1); =20 if (virStrToLong_uip(x, NULL, 10, &def->x) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("cannot parse video x-resolution '%s'"), x); - goto cleanup; + return -1; } =20 if (virStrToLong_uip(y, NULL, 10, &def->y) < 0) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("cannot parse video y-resolution '%s'"), y); - goto cleanup; + return -1; } =20 - cleanup: - return g_steal_pointer(&def); + if (def->x =3D=3D 0 || def->y =3D=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("resolution values must be greater than 0")); + return -1; + } + + *res =3D g_steal_pointer(&def); + return 0; } =20 static virDomainVideoDriverDefPtr @@ -15458,7 +15470,11 @@ virDomainVideoDefParseXML(virDomainXMLOptionPtr xm= lopt, } =20 def->accel =3D virDomainVideoAccelDefParseXML(cur); - def->res =3D virDomainVideoResolutionDefParseXML(cur); + if (virDomainVideoResolutionDefParseXML(cur, &def->res) < = 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + "%s", _("Cannot parse video resolution"= )); + goto error; + } } if (virXMLNodeNameEqual(cur, "driver")) { if (virDomainVirtioOptionsParseXML(cur, &def->virtio) < 0) --=20 2.21.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list