From nobody Mon Feb 9 09:22:12 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.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.129.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=1637601184; cv=none; d=zohomail.com; s=zohoarc; b=RTexKc/w+GlT2OU4a9A18eEVRPXSVxd12S4ty4b5p0jzyLqaBVilU3eilmt+++KboIPuy+yC0Y2rHoi71BodXB4E42WgKhj+Jvjz5thm+A7aSxF42egVzpZb0svG5ZRkX9KL7HcHFHB7gboD4D/CkR7lfybx37xiLhygwE3NbsI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637601184; h=Content-Type:Content-Transfer-Encoding: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=7URl7U8TVc10n5SvqpGNXab7Ncl4Payy1EoSECpCovM=; b=n292/wcl/NgWWaHoP0KCxOdIsA5VWTprqXIEueXgL4Eyyy0fz/OdqrWHa4gOLSaNL60vnM6UbAp6RPKU9DOOKbdKb5ylxmZPDKiRKyIO4HVFDzHMQtopffowsERwgIsI4VbD5iQPEqzi8Z4ofOTdZjSifd1yHYdmhrv2XE0NomA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 163760118406987.75365369552355; Mon, 22 Nov 2021 09:13:04 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-169-d6xD1JcnMcKz59vhehM2oA-1; Mon, 22 Nov 2021 12:12:59 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3C87C1906809; Mon, 22 Nov 2021 17:12:52 +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 2E44E60CD1; Mon, 22 Nov 2021 17:12:51 +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 E3FBD4E590; Mon, 22 Nov 2021 17:12:50 +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 1AMHCiOo029346 for ; Mon, 22 Nov 2021 12:12:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id F1CCC60C7F; Mon, 22 Nov 2021 17:12:44 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.20]) by smtp.corp.redhat.com (Postfix) with ESMTP id 41EB760C5F for ; Mon, 22 Nov 2021 17:12:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637601182; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=7URl7U8TVc10n5SvqpGNXab7Ncl4Payy1EoSECpCovM=; b=Wl1ungxR5uvjov8dA5/B2Vo7ByI6ldyS3zHHAGDozzyCaa9cUDXLJKlY9Lv811dxpnt+PM GuV165AeoFMB3TeQIrGYiD1vusFJAKaikknNIQNx1NmVpxAwpSPJ/15NQCesOTdWhNvx+j al9IGDEQP4n/utePvibNdXxHVNnm0tU= X-MC-Unique: d6xD1JcnMcKz59vhehM2oA-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 08/12] virSecurityLabelDefParseXML: Don't use 'virXPathStringLimit' Date: Mon, 22 Nov 2021 18:12:28 +0100 Message-Id: <723df54c84ac607358036171081aac0542ea410f.1637600984.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com 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.12 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) X-ZM-MESSAGEID: 1637601185669100001 Content-Type: text/plain; charset="utf-8" virXPathStringLimit doesn't give callers a way to differentiate between the queried XPath being empty and the length limit being exceeded. This means that callers are either overwriting the error message or ignoring it altogether. Move the length checks into the caller. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/conf/domain_conf.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index ee44bbbd4b..bd9da0744d 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -7871,9 +7871,9 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, if (seclabel->type =3D=3D VIR_DOMAIN_SECLABEL_STATIC || (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) && seclabel->type !=3D VIR_DOMAIN_SECLABEL_NONE)) { - seclabel->label =3D virXPathStringLimit("string(./label[1])", - VIR_SECURITY_LABEL_BUFLEN-1,= ctxt); - if (!seclabel->label) { + seclabel->label =3D virXPathString("string(./label[1])", ctxt); + if (!seclabel->label || + strlen(seclabel->label) >=3D VIR_SECURITY_LABEL_BUFLEN - 1) { virReportError(VIR_ERR_XML_ERROR, "%s", _("security label is missing")); return NULL; @@ -7884,9 +7884,10 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, if (seclabel->relabel && (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE) && seclabel->type !=3D VIR_DOMAIN_SECLABEL_NONE)) { - seclabel->imagelabel =3D virXPathStringLimit("string(./imagelabel[= 1])", - VIR_SECURITY_LABEL_BUFL= EN-1, ctxt); - if (!seclabel->imagelabel) { + seclabel->imagelabel =3D virXPathString("string(./imagelabel[1])",= ctxt); + + if (!seclabel->imagelabel || + strlen(seclabel->imagelabel) >=3D VIR_SECURITY_LABEL_BUFLEN - = 1) { virReportError(VIR_ERR_XML_ERROR, "%s", _("security imagelabel is missing")); return NULL; @@ -7895,8 +7896,13 @@ virSecurityLabelDefParseXML(xmlXPathContextPtr ctxt, /* Only parse baselabel for dynamic label type */ if (seclabel->type =3D=3D VIR_DOMAIN_SECLABEL_DYNAMIC) { - seclabel->baselabel =3D virXPathStringLimit("string(./baselabel[1]= )", - VIR_SECURITY_LABEL_BUFLE= N-1, ctxt); + seclabel->baselabel =3D virXPathString("string(./baselabel[1])", c= txt); + + if (seclabel->baselabel && + strlen(seclabel->baselabel) >=3D VIR_SECURITY_LABEL_BUFLEN - 1= ) { + g_free(seclabel->baselabel); + seclabel->baselabel =3D NULL; + } } return g_steal_pointer(&seclabel); --=20 2.31.1