From nobody Sun Feb 8 14:57:17 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 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=1570484997; cv=none; d=zoho.com; s=zohoarc; b=TJGOuNFEeVzIFqh/6lNOmnfYBy2leQEJTYBxnsu9g1b2sNKBIgCRZWyGelWzA3gQFXiYnRNyk2AfdNojL37oawWYlcGafWpikGNa3e0IuOzenLGjJu/oqG8nVVrQK7QalurwBM01uNbmjcTLDWWZ+VRiE6on7rOemdE2A7wV+tM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570484997; 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:ARC-Authentication-Results; bh=WElK69WwTq5tW09hwRCCPa6mz5lhrDBfTZ5pUXY1PIQ=; b=YZD2ibXkQo4mkKr8qFLoV069CjDVTe33sWzCm0fY4YJsFM4rotn3Qa7ST8PviYEpmtobXBt1SuK4x1lhXxdTN+pvlp7HdIg3pdoOQ0myNVtTQqlJd4MQQpM8QNiQQoXVSLjl2b0+ShnnfY3LNjkO856QlWYHmuUxW4AEOP6WCGU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1570484997056564.1058193076917; Mon, 7 Oct 2019 14:49:57 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3F7EB308FC22; Mon, 7 Oct 2019 21:49:55 +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 1CA9E5C240; Mon, 7 Oct 2019 21:49:55 +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 D3E8A4EE75; Mon, 7 Oct 2019 21:49:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x97LnVoD014614 for ; Mon, 7 Oct 2019 17:49:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id DB0185C219; Mon, 7 Oct 2019 21:49:31 +0000 (UTC) Received: from worklaptop.redhat.com (ovpn-123-156.rdu2.redhat.com [10.10.123.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D2D05C1D4; Mon, 7 Oct 2019 21:49:31 +0000 (UTC) From: Cole Robinson To: libvir-list@redhat.com Date: Mon, 7 Oct 2019 17:49:26 -0400 Message-Id: <16d9ed51f14f1c74afce25c58aeedd85b0ec6daa.1570482718.git.crobinso@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 12/30] storagefile: Fix backing format \0 check 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Mon, 07 Oct 2019 21:49:55 +0000 (UTC) Content-Type: text/plain; charset="utf-8" >From qemu.git docs/interop/qcow2.txt =3D=3D String header extensions =3D=3D Some header extensions (such as the backing file format name and the external data file name) are just a single string. In this case, the header extension length is the string length and the string is not '\0' terminated. (The header extension padding can make it look like a string is '\0' terminated, but neither is padding always necessary nor is there a guarantee that zero bytes are used for padding.) So we shouldn't be checking for a \0 byte at the end of the backing format section. I think in practice there always is a \0 but we shouldn't depend on that. Signed-off-by: Cole Robinson --- src/util/virstoragefile.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c index 8cd576a463..5a4e4b24ae 100644 --- a/src/util/virstoragefile.c +++ b/src/util/virstoragefile.c @@ -506,13 +506,18 @@ qcow2GetExtensions(const char *buf, case QCOW2_HDR_EXTENSION_END: goto done; =20 - case QCOW2_HDR_EXTENSION_BACKING_FORMAT: - if (buf[offset+len] !=3D '\0') - break; - *backingFormat =3D virStorageFileFormatTypeFromString(buf+offs= et); + case QCOW2_HDR_EXTENSION_BACKING_FORMAT: { + VIR_AUTOFREE(char *) tmp =3D NULL; + if (VIR_ALLOC_N(tmp, len + 1) < 0) + return -1; + memcpy(tmp, buf + offset, len); + tmp[len] =3D '\0'; + + *backingFormat =3D virStorageFileFormatTypeFromString(tmp); if (*backingFormat <=3D VIR_STORAGE_FILE_NONE) return -1; } + } =20 offset +=3D len; } --=20 2.23.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list