From nobody Fri May 17 03:39:32 2024 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=1621927980; cv=none; d=zohomail.com; s=zohoarc; b=Y7qTwq3INWzFzVVfU+bhaR7wbGYAsJE9DW6ftyzJ6TKLjz8J2jsBC366rDwO+9n7ilt+Mg18LLQQ0N1rpwDqP/pt2l0r21oWgKqzB5jBipq2AbQV0pOtHyCYkgh7Q9IRglN/HZvNVYa8R1Q6YZyfF1vHZz3yvMep2iAfrJPyUGg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1621927980; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=roiIElCcFTOWvwxiCJ+KR2cDEaCK0zemjUsIgcTKVrg=; b=Vfxn5TDXSntIpDw4nnlvDIJ0JliDJq9OaHi8zCau5WH60VChmJml/VizdIdh/s99Aeg4O8IvtP8swNQzsGH6oDHpRjhmjWy8ieGzYWEqGq024iX1yDalXrHktYNycj/u2oBAzMcL3PbuELBTw+yQFl62ULxA3a7TGGarqkgd4AA= 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 1621927980711179.261870339418; Tue, 25 May 2021 00:33:00 -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-394-wi29_Sd5Oe-dPpWKnD7R2A-1; Tue, 25 May 2021 03:32:57 -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 93D8C100CCA9; Tue, 25 May 2021 07:32:52 +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 A523960C05; Tue, 25 May 2021 07:32:50 +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 4D7CF1800BB8; Tue, 25 May 2021 07:32:42 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 14P7We5D020321 for ; Tue, 25 May 2021 03:32:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 42C75E143; Tue, 25 May 2021 07:32:40 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.195.11]) by smtp.corp.redhat.com (Postfix) with ESMTP id BA0DDCFF0 for ; Tue, 25 May 2021 07:32:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1621927979; 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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=roiIElCcFTOWvwxiCJ+KR2cDEaCK0zemjUsIgcTKVrg=; b=Y763s+r6jWs3DWufcDGkUO0npve/AOZ5nAoTwo5s1gE4TzGkvbht6CLJ8U+QK8H50uPkHx eHLEfVCvLKbHsJnsATItjmmf6hg2qD2/VDw1FymcrENzHarnGuJWbLGPGzFmDUg29KVZK4 suXm/Fx7HrPJFpikAjviI/E1n1J32uw= X-MC-Unique: wi29_Sd5Oe-dPpWKnD7R2A-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH for 7.4.0] conf: Avoid double indentation of element Date: Tue, 25 May 2021 09:32:35 +0200 Message-Id: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 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. Signed-off-by: Michal Privoznik Tested-by: Bjoern Walk --- I've raised this issue with libxml2 team: https://gitlab.gnome.org/GNOME/libxml2/-/commit/85b1792e37b131e7a51af98a37f= 92472e8de5f3f but I'm not sure it'll be fixed. Unfortunately, the patch that's causing us trouble is being backported all over the place, because it's supposedly fixing a regression. src/conf/domain_conf.c | 9 ++++++++- src/conf/network_conf.c | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 4f78b7b43d..84a8c269be 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -27808,6 +27808,7 @@ virDomainDefFormatInternalSetRootName(virDomainDef = *def, =20 if (def->metadata) { g_autoptr(xmlBuffer) xmlbuf =3D NULL; + const char *xmlbufContent =3D NULL; int oldIndentTreeOutput =3D xmlIndentTreeOutput; =20 /* Indentation on output requires that we previously set @@ -27824,7 +27825,13 @@ virDomainDefFormatInternalSetRootName(virDomainDef= *def, xmlIndentTreeOutput =3D oldIndentTreeOutput; return -1; } - virBufferAsprintf(buf, "%s\n", (char *) xmlBufferContent(xmlbuf)); + + /* After libxml2-v2.9.12-2-g85b1792e even the first line is indent= ed. + * 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 diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index a9eadff29c..20c6dc091a 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -2488,6 +2488,7 @@ virNetworkDefFormatBuf(virBuffer *buf, =20 if (def->metadata) { g_autoptr(xmlBuffer) xmlbuf =3D NULL; + const char *xmlbufContent =3D NULL; int oldIndentTreeOutput =3D xmlIndentTreeOutput; =20 /* Indentation on output requires that we previously set @@ -2504,7 +2505,13 @@ virNetworkDefFormatBuf(virBuffer *buf, xmlIndentTreeOutput =3D oldIndentTreeOutput; return -1; } - virBufferAsprintf(buf, "%s\n", (char *) xmlBufferContent(xmlbuf)); + + /* After libxml2-v2.9.12-2-g85b1792e even the first line is indent= ed. + * 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 --=20 2.26.3