From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45082) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vi3BX-0004gS-Uc for qemu-devel@nongnu.org; Sun, 17 Nov 2013 09:18:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vi3BR-0005XI-Vp for qemu-devel@nongnu.org; Sun, 17 Nov 2013 09:18:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42595) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vi3BR-0005XE-Nx for qemu-devel@nongnu.org; Sun, 17 Nov 2013 09:18:41 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rAHEIe3d004527 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 17 Nov 2013 09:18:41 -0500 From: Max Reitz Date: Sun, 17 Nov 2013 15:18:41 +0100 Message-Id: <1384697924-16918-2-git-send-email-mreitz@redhat.com> In-Reply-To: <1384697924-16918-1-git-send-email-mreitz@redhat.com> References: <1384697924-16918-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH 1/4] qcow2: Move reading nb_snapshots in qcow2_open List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi , Max Reitz Any goto fail between having read nb_snapshots (returning a non-zero value) and allocating s->snapshots (through qcow2_read_snapshots()) results in qcow2_free_snapshots() being called, dereferencing s->snapshots which is still NULL. Fix this by moving the reading of nb_snapshots right before the call to qcow2_read_snapshots(). Signed-off-by: Max Reitz --- block/qcow2.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/block/qcow2.c b/block/qcow2.c index 6e5d98d..3e612a8 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -558,9 +558,6 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags, s->refcount_table_size = header.refcount_table_clusters << (s->cluster_bits - 3); - s->snapshots_offset = header.snapshots_offset; - s->nb_snapshots = header.nb_snapshots; - /* read the level 1 table */ s->l1_size = header.l1_size; @@ -637,6 +634,9 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags, bs->backing_file[len] = '\0'; } + s->snapshots_offset = header.snapshots_offset; + s->nb_snapshots = header.nb_snapshots; + ret = qcow2_read_snapshots(bs); if (ret < 0) { error_setg_errno(errp, -ret, "Could not read snapshots"); -- 1.8.4.2