From nobody Mon Feb 9 07:05:25 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1608248018; cv=none; d=zohomail.com; s=zohoarc; b=arQMN0RvOdNrPtWyG/cuBLDfkiIfRwnig5yZP7biJUOxYYu9vQfGccV+z1NBTdZkYR1F0RvjjRbtBxdvV1PlhjjWdlLCq3d+Ps8biYb+6ILu87UNCV7vuV+OD/aL/xT+xP+HbNTKRUDrBGlXPBL9BWSb7BRrJJGx5ItZKkzKoKQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1608248018; h=Content-Type:Content-Transfer-Encoding:Cc: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=/4oFsvAyawICVJ675Gktd9otrVuNUujzqwmrptFhDsA=; b=HlrlvezO7fGddYTo8S2wuSjERuUtONcW4Q+IU5CYCzrOluKqmqGF3LAQaZtkNdf9NrPcNbD4/Qm+rYXkt9Cl90D9IRTOn42LBjWG6Cz5sSpf3MJ8c0ABBgFHHuCSBHA9fBYknGC0JEOETzSSAoD81/R5twexbhmgkAzxmR+4/KI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1608248018676694.3347576757711; Thu, 17 Dec 2020 15:33:38 -0800 (PST) Received: from localhost ([::1]:59570 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kpw4z-0007si-8s for importer@patchew.org; Thu, 17 Dec 2020 11:24:37 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:52980) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kpw0m-0002Eh-3M for qemu-devel@nongnu.org; Thu, 17 Dec 2020 11:20:16 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:58281) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kpw0g-0005Om-Cj for qemu-devel@nongnu.org; Thu, 17 Dec 2020 11:20:15 -0500 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-464-18eYt8G4PG6bR9iBO3YlQw-1; Thu, 17 Dec 2020 11:20:07 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C39C8801817; Thu, 17 Dec 2020 16:20:06 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-112-103.ams2.redhat.com [10.36.112.103]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6B74010016FE; Thu, 17 Dec 2020 16:20:06 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 89A1611275EC; Thu, 17 Dec 2020 17:20:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1608222009; 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=/4oFsvAyawICVJ675Gktd9otrVuNUujzqwmrptFhDsA=; b=Z/4bshN0YLAp81dwCKdSFr/ILFkkVghgmf0kBaXQ17D/9TMKeu/JjpsIikaRviEOhx+PuV pePzvUCTVb4d4MrfPery3zBwEodrznA9+QsTTwkGGUQmG8JXM/SsI2hMAu+itesIQgdRLI bZ6ebHSwYpxc53VvjmDEEvViY/efQhg= X-MC-Unique: 18eYt8G4PG6bR9iBO3YlQw-1 From: Markus Armbruster To: qemu-devel@nongnu.org Subject: [PATCH 9/9] block/vpc: Use sizeof() instead of HEADER_SIZE for footer size Date: Thu, 17 Dec 2020 17:20:03 +0100 Message-Id: <20201217162003.1102738-10-armbru@redhat.com> In-Reply-To: <20201217162003.1102738-1-armbru@redhat.com> References: <20201217162003.1102738-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=armbru@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=63.128.21.124; envelope-from=armbru@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, mrezanin@redhat.com, qemu-block@nongnu.org, mreitz@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Signed-off-by: Markus Armbruster Reviewed-by: Max Reitz --- block/vpc.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index aac13788df..17a705b482 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -39,8 +39,6 @@ =20 /**************************************************************/ =20 -#define HEADER_SIZE 512 - //#define CACHE =20 enum vhd_type { @@ -253,7 +251,7 @@ static int vpc_open(BlockDriverState *bs, QDict *option= s, int flags, goto fail; } =20 - ret =3D bdrv_pread(bs->file, 0, &s->footer, HEADER_SIZE); + ret =3D bdrv_pread(bs->file, 0, &s->footer, sizeof(s->footer)); if (ret < 0) { error_setg(errp, "Unable to read VHD header"); goto fail; @@ -266,15 +264,15 @@ static int vpc_open(BlockDriverState *bs, QDict *opti= ons, int flags, ret =3D offset; error_setg(errp, "Invalid file size"); goto fail; - } else if (offset < HEADER_SIZE) { + } else if (offset < sizeof(*footer)) { ret =3D -EINVAL; error_setg(errp, "File too small for a VHD header"); goto fail; } =20 /* If a fixed disk, the footer is found only at the end of the fil= e */ - ret =3D bdrv_pread(bs->file, offset - HEADER_SIZE, footer, - HEADER_SIZE); + ret =3D bdrv_pread(bs->file, offset - sizeof(*footer), + footer, sizeof(*footer)); if (ret < 0) { goto fail; } @@ -288,7 +286,7 @@ static int vpc_open(BlockDriverState *bs, QDict *option= s, int flags, =20 checksum =3D be32_to_cpu(footer->checksum); footer->checksum =3D 0; - if (vpc_checksum(footer, HEADER_SIZE) !=3D checksum) { + if (vpc_checksum(footer, sizeof(*footer)) !=3D checksum) { error_setg(errp, "Incorrect header checksum"); ret =3D -EINVAL; goto fail; @@ -538,7 +536,7 @@ static int rewrite_footer(BlockDriverState *bs) BDRVVPCState *s =3D bs->opaque; int64_t offset =3D s->free_data_block_offset; =20 - ret =3D bdrv_pwrite_sync(bs->file, offset, &s->footer, HEADER_SIZE); + ret =3D bdrv_pwrite_sync(bs->file, offset, &s->footer, sizeof(s->foote= r)); if (ret < 0) return ret; =20 @@ -833,13 +831,13 @@ static int create_dynamic_disk(BlockBackend *blk, VHD= Footer *footer, block_size =3D 0x200000; num_bat_entries =3D DIV_ROUND_UP(total_sectors, block_size / 512); =20 - ret =3D blk_pwrite(blk, offset, footer, HEADER_SIZE, 0); + ret =3D blk_pwrite(blk, offset, footer, sizeof(*footer), 0); if (ret < 0) { goto fail; } =20 offset =3D 1536 + ((num_bat_entries * 4 + 511) & ~511); - ret =3D blk_pwrite(blk, offset, footer, HEADER_SIZE, 0); + ret =3D blk_pwrite(blk, offset, footer, sizeof(*footer), 0); if (ret < 0) { goto fail; } @@ -893,14 +891,15 @@ static int create_fixed_disk(BlockBackend *blk, VHDFo= oter *footer, int ret; =20 /* Add footer to total size */ - total_size +=3D HEADER_SIZE; + total_size +=3D sizeof(*footer); =20 ret =3D blk_truncate(blk, total_size, false, PREALLOC_MODE_OFF, 0, err= p); if (ret < 0) { return ret; } =20 - ret =3D blk_pwrite(blk, total_size - HEADER_SIZE, footer, HEADER_SIZE,= 0); + ret =3D blk_pwrite(blk, total_size - sizeof(*footer), + footer, sizeof(*footer), 0); if (ret < 0) { error_setg_errno(errp, -ret, "Unable to write VHD header"); return ret; @@ -1035,7 +1034,7 @@ static int coroutine_fn vpc_co_create(BlockdevCreateO= ptions *opts, } =20 /* Prepare the Hard Disk Footer */ - memset(&footer, 0, HEADER_SIZE); + memset(&footer, 0, sizeof(footer)); =20 memcpy(footer.creator, "conectix", 8); if (vpc_opts->force_size) { @@ -1048,7 +1047,7 @@ static int coroutine_fn vpc_co_create(BlockdevCreateO= ptions *opts, footer.features =3D cpu_to_be32(0x02); footer.version =3D cpu_to_be32(0x00010000); if (disk_type =3D=3D VHD_DYNAMIC) { - footer.data_offset =3D cpu_to_be64(HEADER_SIZE); + footer.data_offset =3D cpu_to_be64(sizeof(footer)); } else { footer.data_offset =3D cpu_to_be64(0xFFFFFFFFFFFFFFFFULL); } @@ -1068,7 +1067,7 @@ static int coroutine_fn vpc_co_create(BlockdevCreateO= ptions *opts, qemu_uuid_generate(&uuid); footer.uuid =3D uuid; =20 - footer.checksum =3D cpu_to_be32(vpc_checksum(&footer, HEADER_SIZE)); + footer.checksum =3D cpu_to_be32(vpc_checksum(&footer, sizeof(footer))); =20 if (disk_type =3D=3D VHD_DYNAMIC) { ret =3D create_dynamic_disk(blk, &footer, total_sectors); --=20 2.26.2