From nobody Mon Feb 9 05:40:41 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=1621936146; cv=none; d=zohomail.com; s=zohoarc; b=mwQGWrRvXMReAZZWOGk4dOz02GCpXoEn4eP0NBcgh1BUcZTutuSs9j05b74nM0qsNi3MHpOSxVNIpl47x/l+1AhA0jQWV3dQptfbM638eJFMPmM/fuHwz4UIJdem/6HjIytQQ7MaJ+xPPUbXuBWpKAckaztXKDWDGUD8uoWrrtI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621936146; 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=BM3XsAz22WgS2PNBEKpEy3D9DIh2j3WaliQviBcspBQ=; b=mldLdbv0QlaCBFeAgxWLl4pcwqiyX2UKTdv4mzDTw19LCLUSneznaSQr9Zc9lJHQnjIJyw6W6eNide0G06MszISDQhXHkdsukGH15lhwtjhChsK7m69P9dcGdoEeB3xMVptTbLsHJ0stKuoa82sU+pny2QythfQnaS7QDkrkuvQ= 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 1621936146221924.4489506611367; Tue, 25 May 2021 02:49:06 -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-220-it58kgz-MhyBhdWSDM0GrA-1; Tue, 25 May 2021 05:49:03 -0400 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 6BAB8107ACE4; Tue, 25 May 2021 09:48:58 +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 49DA07058A; Tue, 25 May 2021 09:48:58 +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 0FA4B55348; Tue, 25 May 2021 09:48:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 14P9maAL031366 for ; Tue, 25 May 2021 05:48:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7A5A7690FA; Tue, 25 May 2021 09:48:36 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id F3BAA19CB6 for ; Tue, 25 May 2021 09:48:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621936145; 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=BM3XsAz22WgS2PNBEKpEy3D9DIh2j3WaliQviBcspBQ=; b=cL7Cqz39jo0D/t1XEcUR5gVJdpPWM8b6PUlbtUtEU5kmQjn3gqwjetJZj2OnIqAse9xEUR B/MLJ/cWQF5iiJq6430wtmzqeYqAG0bgV0u+h8CvTitVKDYaVhq+r5olvXPZk7gxxUel7c KmnztR/jqENd7U7BS29u9NNgtlHUOgQ= X-MC-Unique: it58kgz-MhyBhdWSDM0GrA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH v2 3/3] virxml: Avoid double indentation of element Date: Tue, 25 May 2021 11:48:28 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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) Content-Type: text/plain; charset="utf-8" There was a recent change in libxml2 that caused a trouble for us. To us, in domain or network XMLs are just opaque value where management application can store whatever data it finds fit. At XML parser/formatter level, we just make a copy of the element during parsing and then format it back. For formatting we use xmlNodeDump() which allows caller to specify level of indentation. Previously, the indentation was not applied onto the very first line, but as of v2.9.12-2-g85b1792e libxml2 is applying indentation also on the first line. This does not work well with out virBuffer because as soon as we call virBufferAsprintf() to append element, virBufferAsprintf() will apply another level of indentation. Instead of version checking, let's skip any indentation added by libxml2 before virBufferAsprintf() is called. Note, the problem is only when telling xmlNodeDump() to use indentation, i.e. level argument is not zero. Therefore, virXMLNodeToString() which also calls xmlNodeDump() is safe as it passes zero. Tested-by: Bjoern Walk Signed-off-by: Michal Privoznik --- src/util/virxml.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/util/virxml.c b/src/util/virxml.c index 91c6f6b02e..4360b15486 100644 --- a/src/util/virxml.c +++ b/src/util/virxml.c @@ -1723,6 +1723,7 @@ virXMLFormatMetadata(virBuffer *buf, xmlNodePtr metadata) { g_autoptr(xmlBuffer) xmlbuf =3D NULL; + const char *xmlbufContent =3D NULL; int oldIndentTreeOutput =3D xmlIndentTreeOutput; =20 if (!metadata) @@ -1745,7 +1746,12 @@ virXMLFormatMetadata(virBuffer *buf, return -1; } =20 - virBufferAsprintf(buf, "%s\n", (char *) xmlBufferContent(xmlbuf)); + /* After libxml2-v2.9.12-2-g85b1792e even the first line is indented. + * But virBufferAsprintf() also adds indentation. Skip one of them. */ + xmlbufContent =3D (const char *) xmlBufferContent(xmlbuf); + virSkipSpaces(&xmlbufContent); + + virBufferAsprintf(buf, "%s\n", xmlbufContent); xmlIndentTreeOutput =3D oldIndentTreeOutput; =20 return 0; --=20 2.26.3