From nobody Sat Apr 27 14:45:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1502138022100466.8878549405064; Mon, 7 Aug 2017 13:33:42 -0700 (PDT) Received: from localhost ([::1]:39456 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1deoia-0000km-N9 for importer@patchew.org; Mon, 07 Aug 2017 16:33:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45873) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1deofY-0007Fz-1Y for qemu-devel@nongnu.org; Mon, 07 Aug 2017 16:30:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1deofT-00047n-88 for qemu-devel@nongnu.org; Mon, 07 Aug 2017 16:30:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60362) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1deofI-0003wF-Dp; Mon, 07 Aug 2017 16:30:16 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5F7EC267CD; Mon, 7 Aug 2017 20:30:15 +0000 (UTC) Received: from red.redhat.com (ovpn-120-43.rdu2.redhat.com [10.10.120.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id CFD875D9C0; Mon, 7 Aug 2017 20:30:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 5F7EC267CD Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 7 Aug 2017 15:30:04 -0500 Message-Id: <20170807203007.19033-2-eblake@redhat.com> In-Reply-To: <20170807203007.19033-1-eblake@redhat.com> References: <20170807203007.19033-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 07 Aug 2017 20:30:15 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/4] vpc: Check failure of bdrv_getlength() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, armbru@redhat.com, qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" vpc_open() was checking for bdrv_getlength() failure in one, but not the other, location. Reported-by: Markus Armbruster Signed-off-by: Eric Blake Reviewed-by: Jeff Cody Reviewed-by: John Snow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- block/vpc.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/block/vpc.c b/block/vpc.c index 574879ba7c..468d10ec1c 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -219,6 +219,7 @@ static int vpc_open(BlockDriverState *bs, QDict *option= s, int flags, uint64_t pagetable_size; int disk_type =3D VHD_DYNAMIC; int ret; + int64_t bs_size; bs->file =3D bdrv_open_child(NULL, options, "file", bs, &child_file, false, errp); @@ -411,7 +412,13 @@ static int vpc_open(BlockDriverState *bs, QDict *optio= ns, int flags, } } - if (s->free_data_block_offset > bdrv_getlength(bs->file->bs)) { + bs_size =3D bdrv_getlength(bs->file->bs); + if (bs_size < 0) { + error_setg_errno(errp, -bs_size, "unable to learn image size"); + ret =3D bs_size; + goto fail; + } + if (s->free_data_block_offset > bs_size) { error_setg(errp, "block-vpc: free_data_block_offset points aft= er " "the end of file. The image has been truncate= d."); ret =3D -EINVAL; --=20 2.13.4 From nobody Sat Apr 27 14:45:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1502137916422397.5903001318093; Mon, 7 Aug 2017 13:31:56 -0700 (PDT) Received: from localhost ([::1]:39453 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1deogt-000858-6m for importer@patchew.org; Mon, 07 Aug 2017 16:31:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45885) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1deofa-0007II-8L for qemu-devel@nongnu.org; Mon, 07 Aug 2017 16:30:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1deofU-00048X-MI for qemu-devel@nongnu.org; Mon, 07 Aug 2017 16:30:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60472) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1deofJ-0003xb-Jo; Mon, 07 Aug 2017 16:30:17 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 92AB4356F3; Mon, 7 Aug 2017 20:30:16 +0000 (UTC) Received: from red.redhat.com (ovpn-120-43.rdu2.redhat.com [10.10.120.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9DF365D96D; Mon, 7 Aug 2017 20:30:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 92AB4356F3 Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 7 Aug 2017 15:30:05 -0500 Message-Id: <20170807203007.19033-3-eblake@redhat.com> In-Reply-To: <20170807203007.19033-1-eblake@redhat.com> References: <20170807203007.19033-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 07 Aug 2017 20:30:16 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 2/4] qcow: Check failure of bdrv_getlength() and bdrv_truncate() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, armbru@redhat.com, qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" This also requires changing the return type of get_cluster_offset() and adjusting all callers. Use osdep.h macros instead of open-coded rounding while in the area. Reported-by: Markus Armbruster Signed-off-by: Eric Blake Reviewed-by: Jeff Cody Reviewed-by: John Snow Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- block/qcow.c | 64 ++++++++++++++++++++++++++++++++++++++++++--------------= ---- 1 file changed, 45 insertions(+), 19 deletions(-) diff --git a/block/qcow.c b/block/qcow.c index c08cdc4a7b..937023d447 100644 --- a/block/qcow.c +++ b/block/qcow.c @@ -347,16 +347,17 @@ static int qcow_reopen_prepare(BDRVReopenState *state, * 'compressed_size'. 'compressed_size' must be > 0 and < * cluster_size * - * return 0 if not allocated. + * return 0 if not allocated, -errno on failure. */ -static uint64_t get_cluster_offset(BlockDriverState *bs, - uint64_t offset, int allocate, - int compressed_size, - int n_start, int n_end) +static int64_t get_cluster_offset(BlockDriverState *bs, + uint64_t offset, int allocate, + int compressed_size, + int n_start, int n_end) { BDRVQcowState *s =3D bs->opaque; int min_index, i, j, l1_index, l2_index; - uint64_t l2_offset, *l2_table, cluster_offset, tmp; + int64_t l2_offset, cluster_offset; + uint64_t *l2_table, tmp; uint32_t min_count; int new_l2_table; @@ -368,8 +369,11 @@ static uint64_t get_cluster_offset(BlockDriverState *b= s, return 0; /* allocate a new l2 entry */ l2_offset =3D bdrv_getlength(bs->file->bs); + if (l2_offset < 0) { + return l2_offset; + } /* round to cluster size */ - l2_offset =3D (l2_offset + s->cluster_size - 1) & ~(s->cluster_siz= e - 1); + l2_offset =3D QEMU_ALIGN_UP(l2_offset, s->cluster_size); /* update the L1 entry */ s->l1_table[l1_index] =3D l2_offset; tmp =3D cpu_to_be64(l2_offset); @@ -430,8 +434,10 @@ static uint64_t get_cluster_offset(BlockDriverState *b= s, if (decompress_cluster(bs, cluster_offset) < 0) return 0; cluster_offset =3D bdrv_getlength(bs->file->bs); - cluster_offset =3D (cluster_offset + s->cluster_size - 1) & - ~(s->cluster_size - 1); + if (cluster_offset < 0) { + return cluster_offset; + } + cluster_offset =3D QEMU_ALIGN_UP(cluster_offset, s->cluster_si= ze); /* write the cluster content */ if (bdrv_pwrite(bs->file, cluster_offset, s->cluster_cache, s->cluster_size) !=3D @@ -439,12 +445,19 @@ static uint64_t get_cluster_offset(BlockDriverState *= bs, return -1; } else { cluster_offset =3D bdrv_getlength(bs->file->bs); + if (cluster_offset < 0) { + return cluster_offset; + } if (allocate =3D=3D 1) { + int ret; + /* round to cluster size */ - cluster_offset =3D (cluster_offset + s->cluster_size - 1) & - ~(s->cluster_size - 1); - bdrv_truncate(bs->file, cluster_offset + s->cluster_size, - PREALLOC_MODE_OFF, NULL); + cluster_offset =3D QEMU_ALIGN_UP(cluster_offset, s->cluste= r_size); + ret =3D bdrv_truncate(bs->file, cluster_offset + s->cluste= r_size, + PREALLOC_MODE_OFF, NULL); + if (ret < 0) { + return ret; + } /* if encrypted, we must initialize the cluster content which won't be written */ if (bs->encrypted && @@ -491,11 +504,14 @@ static int64_t coroutine_fn qcow_co_get_block_status(= BlockDriverState *bs, { BDRVQcowState *s =3D bs->opaque; int index_in_cluster, n; - uint64_t cluster_offset; + int64_t cluster_offset; qemu_co_mutex_lock(&s->lock); cluster_offset =3D get_cluster_offset(bs, sector_num << 9, 0, 0, 0, 0); qemu_co_mutex_unlock(&s->lock); + if (cluster_offset < 0) { + return cluster_offset; + } index_in_cluster =3D sector_num & (s->cluster_sectors - 1); n =3D s->cluster_sectors - index_in_cluster; if (n > nb_sectors) @@ -567,7 +583,7 @@ static coroutine_fn int qcow_co_readv(BlockDriverState = *bs, int64_t sector_num, BDRVQcowState *s =3D bs->opaque; int index_in_cluster; int ret =3D 0, n; - uint64_t cluster_offset; + int64_t cluster_offset; struct iovec hd_iov; QEMUIOVector hd_qiov; uint8_t *buf; @@ -588,8 +604,10 @@ static coroutine_fn int qcow_co_readv(BlockDriverState= *bs, int64_t sector_num, while (nb_sectors !=3D 0) { /* prepare next request */ - cluster_offset =3D get_cluster_offset(bs, sector_num << 9, - 0, 0, 0, 0); + cluster_offset =3D get_cluster_offset(bs, sector_num << 9, 0, 0, 0= , 0); + if (cluster_offset < 0) { + return cluster_offset; + } index_in_cluster =3D sector_num & (s->cluster_sectors - 1); n =3D s->cluster_sectors - index_in_cluster; if (n > nb_sectors) { @@ -670,7 +688,7 @@ static coroutine_fn int qcow_co_writev(BlockDriverState= *bs, int64_t sector_num, { BDRVQcowState *s =3D bs->opaque; int index_in_cluster; - uint64_t cluster_offset; + int64_t cluster_offset; int ret =3D 0, n; struct iovec hd_iov; QEMUIOVector hd_qiov; @@ -704,6 +722,10 @@ static coroutine_fn int qcow_co_writev(BlockDriverStat= e *bs, int64_t sector_num, cluster_offset =3D get_cluster_offset(bs, sector_num << 9, 1, 0, index_in_cluster, index_in_cluster + n); + if (cluster_offset < 0) { + ret =3D cluster_offset; + break; + } if (!cluster_offset || (cluster_offset & 511) !=3D 0) { ret =3D -EIO; break; @@ -949,7 +971,7 @@ qcow_co_pwritev_compressed(BlockDriverState *bs, uint64= _t offset, z_stream strm; int ret, out_len; uint8_t *buf, *out_buf; - uint64_t cluster_offset; + int64_t cluster_offset; buf =3D qemu_blockalign(bs, s->cluster_size); if (bytes !=3D s->cluster_size) { @@ -1003,6 +1025,10 @@ qcow_co_pwritev_compressed(BlockDriverState *bs, uin= t64_t offset, qemu_co_mutex_lock(&s->lock); cluster_offset =3D get_cluster_offset(bs, offset, 2, out_len, 0, 0); qemu_co_mutex_unlock(&s->lock); + if (cluster_offset < 0) { + ret =3D cluster_offset; + goto fail; + } if (cluster_offset =3D=3D 0) { ret =3D -EIO; goto fail; --=20 2.13.4 From nobody Sat Apr 27 14:45:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1502138023830745.9582812195948; Mon, 7 Aug 2017 13:33:43 -0700 (PDT) Received: from localhost ([::1]:39457 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1deoic-0000lt-G4 for importer@patchew.org; Mon, 07 Aug 2017 16:33:42 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45892) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1deofb-0007Iq-1M for qemu-devel@nongnu.org; Mon, 07 Aug 2017 16:30:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1deofW-00049I-8f for qemu-devel@nongnu.org; Mon, 07 Aug 2017 16:30:35 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45914) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1deofM-0003ye-2G; Mon, 07 Aug 2017 16:30:20 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BC8D77F40F; Mon, 7 Aug 2017 20:30:18 +0000 (UTC) Received: from red.redhat.com (ovpn-120-43.rdu2.redhat.com [10.10.120.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id D2CBC5D9C9; Mon, 7 Aug 2017 20:30:16 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BC8D77F40F Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 7 Aug 2017 15:30:06 -0500 Message-Id: <20170807203007.19033-4-eblake@redhat.com> In-Reply-To: <20170807203007.19033-1-eblake@redhat.com> References: <20170807203007.19033-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Mon, 07 Aug 2017 20:30:19 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 3/4] qcow2: Drop debugging dump_refcounts() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, armbru@redhat.com, qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" It's been #if 0'd since its introduction in 2006, commit 585f8587. We can revive dead code if we need it, but in the meantime, it has bit-rotted (for example, not checking for failure in bdrv_getlength()). Signed-off-by: Eric Blake Reviewed-by: Jeff Cody Reviewed-by: John Snow Reviewed-by: Kevin Wolf Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- block/qcow2.c | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index d7c600b5a2..99407403ea 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3798,27 +3798,6 @@ static ImageInfoSpecific *qcow2_get_specific_info(Bl= ockDriverState *bs) return spec_info; } -#if 0 -static void dump_refcounts(BlockDriverState *bs) -{ - BDRVQcow2State *s =3D bs->opaque; - int64_t nb_clusters, k, k1, size; - int refcount; - - size =3D bdrv_getlength(bs->file->bs); - nb_clusters =3D size_to_clusters(s, size); - for(k =3D 0; k < nb_clusters;) { - k1 =3D k; - refcount =3D get_refcount(bs, k); - k++; - while (k < nb_clusters && get_refcount(bs, k) =3D=3D refcount) - k++; - printf("%" PRId64 ": refcount=3D%d nb=3D%" PRId64 "\n", k, refcoun= t, - k - k1); - } -} -#endif - static int qcow2_save_vmstate(BlockDriverState *bs, QEMUIOVector *qiov, int64_t pos) { --=20 2.13.4 From nobody Sat Apr 27 14:45:15 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1502138129747382.58524260907495; Mon, 7 Aug 2017 13:35:29 -0700 (PDT) Received: from localhost ([::1]:39470 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1deokK-0002c0-HC for importer@patchew.org; Mon, 07 Aug 2017 16:35:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45905) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1deofd-0007KO-0x for qemu-devel@nongnu.org; Mon, 07 Aug 2017 16:30:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1deofY-00049w-8D for qemu-devel@nongnu.org; Mon, 07 Aug 2017 16:30:37 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52564) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1deofO-0003zV-3R; Mon, 07 Aug 2017 16:30:22 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 206B013A9F; Mon, 7 Aug 2017 20:30:21 +0000 (UTC) Received: from red.redhat.com (ovpn-120-43.rdu2.redhat.com [10.10.120.43]) by smtp.corp.redhat.com (Postfix) with ESMTP id F246F5D96C; Mon, 7 Aug 2017 20:30:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 206B013A9F Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 7 Aug 2017 15:30:07 -0500 Message-Id: <20170807203007.19033-5-eblake@redhat.com> In-Reply-To: <20170807203007.19033-1-eblake@redhat.com> References: <20170807203007.19033-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Mon, 07 Aug 2017 20:30:21 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 4/4] qcow2: Check failure of bdrv_getlength() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, armbru@redhat.com, qemu-block@nongnu.org, Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" qcow2_co_pwritev_compressed() should not call bdrv_truncate() if determining the size failed. Reported-by: Markus Armbruster Signed-off-by: Eric Blake Reviewed-by: Jeff Cody Reviewed-by: John Snow Reviewed-by: Kevin Wolf Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- block/qcow2.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/block/qcow2.c b/block/qcow2.c index 99407403ea..40ba26c111 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -3282,12 +3282,15 @@ qcow2_co_pwritev_compressed(BlockDriverState *bs, u= int64_t offset, z_stream strm; int ret, out_len; uint8_t *buf, *out_buf; - uint64_t cluster_offset; + int64_t cluster_offset; if (bytes =3D=3D 0) { /* align end of file to a sector boundary to ease reading with sector based I/Os */ cluster_offset =3D bdrv_getlength(bs->file->bs); + if (cluster_offset < 0) { + return cluster_offset; + } return bdrv_truncate(bs->file, cluster_offset, PREALLOC_MODE_OFF, = NULL); } --=20 2.13.4