From nobody Sat Feb 7 04:12:32 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1729589339519332.7046998303606; Tue, 22 Oct 2024 02:28:59 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 85E8118F0; Tue, 22 Oct 2024 05:28:58 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 8F47E1947; Tue, 22 Oct 2024 05:28:14 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id ACC1C18D9; Tue, 22 Oct 2024 05:28:09 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id AC3E218C8 for ; Tue, 22 Oct 2024 05:28:04 -0400 (EDT) Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-593-Mj7RLo1hOSGSdfnRiolDMA-1; Tue, 22 Oct 2024 05:28:03 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 471A919560B0 for ; Tue, 22 Oct 2024 09:28:02 +0000 (UTC) Received: from toolbox.redhat.com (unknown [10.42.28.59]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E2D4B19560A2; Tue, 22 Oct 2024 09:28:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729589284; h=from:from: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; bh=17jkQ3Fg95ztLCIGw2dhEkLO1xjCjubJNmN6edPa1BI=; b=DdU3Z65NeETGAZ4UIb7L37Rrjd6t+ycLIUrfTgF4PixLV5F8VSLNQBZmbgSQ8PdViaDJLo eQ62efpt34/nT9nXZp9r6rMXfqT0qQKF67EprPyS5tV67/Nti6hUHwOyIwssFdkWa0EmPJ 3fPVtf+BHvJxs9Ss25DYdxwyqA1wWRQ= X-MC-Unique: Mj7RLo1hOSGSdfnRiolDMA-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: devel@lists.libvirt.org Cc: "Richard W.M. Jones" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [PATCH v2 2/3] util/xml: don't assume libxml2 has the filename of the document Date: Tue, 22 Oct 2024 10:27:53 +0100 Message-ID: <20241022092754.1542147-3-berrange@redhat.com> In-Reply-To: <20241022092754.1542147-1-berrange@redhat.com> References: <20241022092754.1542147-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: WRG5ZNU4WABZ6UQC3VGWW72OE5SYGJDS X-Message-ID-Hash: WRG5ZNU4WABZ6UQC3VGWW72OE5SYGJDS X-MailFrom: berrange@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1729589341327116600 Content-Type: text/plain; charset="utf-8" The libxml2 error handling gets the filename from a libxml2 struct, but it is better to not assume libxml2 knows the filename being parsed, as we might have simply provided it a pre-loaded string. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: Peter Krempa --- src/util/virxml.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/util/virxml.c b/src/util/virxml.c index 91f736bf39..797aa6f6ca 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -46,6 +46,7 @@ /* Internal data to be passed to SAX parser and used by error handler. */ struct virParserData { int domcode; + const char *filename; }; =20 =20 @@ -1022,7 +1023,7 @@ static void catchXMLError(void *ctx, const char *msg G_GNUC_UNUSED, ...) { xmlParserCtxtPtr ctxt =3D (xmlParserCtxtPtr) ctx; - + struct virParserData *private =3D ctxt->_private; const xmlChar *cur, *base; unsigned int n, col; /* GCC warns if signed, because compared w= ith sizeof() */ int domcode =3D VIR_FROM_XML; @@ -1030,6 +1031,10 @@ catchXMLError(void *ctx, const char *msg G_GNUC_UNUS= ED, ...) g_autofree char *contextstr =3D NULL; g_autofree char *pointerstr =3D NULL; const xmlError *lastError =3D xmlCtxtGetLastError(ctxt); + const char *filename =3D NULL; + + if (private) + filename =3D private->filename; =20 /* conditions for error printing */ if (!ctxt || @@ -1040,9 +1045,8 @@ catchXMLError(void *ctx, const char *msg G_GNUC_UNUSE= D, ...) lastError->message =3D=3D NULL) return; =20 - if (ctxt->_private) - domcode =3D ((struct virParserData *) ctxt->_private)->domcode; - + if (private) + domcode =3D private->domcode; =20 cur =3D ctxt->input->cur; base =3D ctxt->input->base; @@ -1083,10 +1087,10 @@ catchXMLError(void *ctx, const char *msg G_GNUC_UNU= SED, ...) =20 pointerstr =3D virBufferContentAndReset(&buf); =20 - if (lastError->file) { + if (filename) { virGenericReportError(domcode, VIR_ERR_XML_DETAIL, _("%1$s:%2$d: %3$s%4$s\n%5$s"), - lastError->file, + filename, lastError->line, lastError->message, contextstr, @@ -1152,6 +1156,7 @@ virXMLParseHelper(int domcode, abort(); =20 private.domcode =3D domcode; + private.filename =3D filename; pctxt->_private =3D &private; pctxt->sax->error =3D catchXMLError; =20 --=20 2.46.0