From patchwork Fri Jan 18 16:28:34 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Hajnoczi X-Patchwork-Id: 213673 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 061B42C007C for ; Sat, 19 Jan 2013 03:29:24 +1100 (EST) Received: from localhost ([::1]:40798 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TwEok-0001hr-22 for incoming@patchwork.ozlabs.org; Fri, 18 Jan 2013 11:29:22 -0500 Received: from eggs.gnu.org ([208.118.235.92]:53922) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TwEoL-0001Mi-OX for qemu-devel@nongnu.org; Fri, 18 Jan 2013 11:29:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TwEoG-0004sO-Dy for qemu-devel@nongnu.org; Fri, 18 Jan 2013 11:28:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:32663) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TwEoG-0004rg-57 for qemu-devel@nongnu.org; Fri, 18 Jan 2013 11:28:52 -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 r0IGSpi9028320 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 18 Jan 2013 11:28:51 -0500 Received: from localhost (ovpn-112-41.ams2.redhat.com [10.36.112.41]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r0IGSoxq027134; Fri, 18 Jan 2013 11:28:50 -0500 From: Stefan Hajnoczi To: Date: Fri, 18 Jan 2013 17:28:34 +0100 Message-Id: <1358526521-24300-2-git-send-email-stefanha@redhat.com> In-Reply-To: <1358526521-24300-1-git-send-email-stefanha@redhat.com> References: <1358526521-24300-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Anthony Liguori , Jeff Cody , Stefan Hajnoczi Subject: [Qemu-devel] [PATCH 1/8] block: fix null-pointer bug on error case in block commit X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Jeff Cody This is a bug that was caught by a coverity run by Markus. In the error case when we errored out to exit_restore_open early in the function, 'overlay_bs' was still NULL at that point, although it is used to look up flags and perform a bdrv_reopen(). Move the overlay_bs lookup to where it is needed, and check for NULL before restoring the flags. Also get rid of the unneeded parameter initialization. Reported-By: Markus Armbruster Signed-off-by: Jeff Cody Signed-off-by: Stefan Hajnoczi --- block/commit.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/block/commit.c b/block/commit.c index 61ebdba..553447e 100644 --- a/block/commit.c +++ b/block/commit.c @@ -65,7 +65,7 @@ static void coroutine_fn commit_run(void *opaque) BlockDriverState *active = s->active; BlockDriverState *top = s->top; BlockDriverState *base = s->base; - BlockDriverState *overlay_bs = NULL; + BlockDriverState *overlay_bs; int64_t sector_num, end; int ret = 0; int n = 0; @@ -92,8 +92,6 @@ static void coroutine_fn commit_run(void *opaque) } } - overlay_bs = bdrv_find_overlay(active, top); - end = s->common.len >> BDRV_SECTOR_BITS; buf = qemu_blockalign(top, COMMIT_BUFFER_SIZE); @@ -156,7 +154,8 @@ exit_restore_reopen: if (s->base_flags != bdrv_get_flags(base)) { bdrv_reopen(base, s->base_flags, NULL); } - if (s->orig_overlay_flags != bdrv_get_flags(overlay_bs)) { + overlay_bs = bdrv_find_overlay(active, top); + if (overlay_bs && s->orig_overlay_flags != bdrv_get_flags(overlay_bs)) { bdrv_reopen(overlay_bs, s->orig_overlay_flags, NULL); }