From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36689) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W5GYQ-0000SH-GA for qemu-devel@nongnu.org; Mon, 20 Jan 2014 10:14:27 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W5GYL-0007An-T2 for qemu-devel@nongnu.org; Mon, 20 Jan 2014 10:14:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:20273) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W5GYL-0007A3-Ka for qemu-devel@nongnu.org; Mon, 20 Jan 2014 10:14:17 -0500 Date: Mon, 20 Jan 2014 16:14:10 +0100 From: Kevin Wolf Message-ID: <20140120151410.GF3267@dhcp-200-207.str.redhat.com> References: <52DBF958.7090107@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <52DBF958.7090107@redhat.com> Subject: Re: [Qemu-devel] [PATCH v1 2/3] qcow2: fix offset overflow List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz Cc: Hu Tao , qemu-devel@nongnu.org, Stefan Hajnoczi Am 19.01.2014 um 17:12 hat Max Reitz geschrieben: > On 30.12.2013 06:29, Hu Tao wrote: > >When cluster size is big enough it can lead offset overflow > >in qcow2_alloc_clusters_at(). This patch fixes it. > > > >Signed-off-by: Hu Tao > >--- > > block/qcow2-refcount.c | 7 ++++++- > > 1 file changed, 6 insertions(+), 1 deletion(-) > > > >diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c > >index c974abe..b3ebb7f 100644 > >--- a/block/qcow2-refcount.c > >+++ b/block/qcow2-refcount.c > >@@ -676,7 +676,12 @@ int qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset, > > BDRVQcowState *s = bs->opaque; > > uint64_t cluster_index; > > uint64_t old_free_cluster_index; > >- int i, refcount, ret; > >+ uint64_t i; > >+ int refcount, ret; > >+ > >+ if (nb_clusters <= 0) { > >+ return 0; > > I think I'd rather return -EINVAL here. In fact, I think return 0 is fine for nb_clusters == 0, and we should assert(nb_clusters >= 0). Kevin