Received: from eggs.gnu.org ([2001:4830:134:3::10]:53020) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VbCCg-0006Pa-Ig for qemu-devel@nongnu.org; Tue, 29 Oct 2013 12:31:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VbCCb-0001rf-Cr for qemu-devel@nongnu.org; Tue, 29 Oct 2013 12:31:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:64513) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VbCCb-0001rR-5o for qemu-devel@nongnu.org; Tue, 29 Oct 2013 12:31:33 -0400 From: Kevin Wolf Date: Tue, 29 Oct 2013 17:31:03 +0100 Message-Id: <1383064269-27720-12-git-send-email-kwolf@redhat.com> In-Reply-To: <1383064269-27720-1-git-send-email-kwolf@redhat.com> References: <1383064269-27720-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL 11/17] block: Don't copy backing file name on error List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Max Reitz bdrv_open_backing_file() tries to copy the backing file name using pstrcpy directly after calling bdrv_open() to open the backing file without checking whether that was actually successful. If it was not, ps->backing_hd->file will probably be NULL and qemu will crash. Fix this by moving pstrcpy after checking whether bdrv_open() succeeded. Signed-off-by: Max Reitz Reviewed-by: Benoit Canet Reviewed-by: Amos Kong Signed-off-by: Kevin Wolf --- block.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/block.c b/block.c index fd05a80..366999b 100644 --- a/block.c +++ b/block.c @@ -1004,8 +1004,6 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp) ret = bdrv_open(bs->backing_hd, *backing_filename ? backing_filename : NULL, options, back_flags, back_drv, &local_err); - pstrcpy(bs->backing_file, sizeof(bs->backing_file), - bs->backing_hd->file->filename); if (ret < 0) { bdrv_unref(bs->backing_hd); bs->backing_hd = NULL; @@ -1013,6 +1011,8 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp) error_propagate(errp, local_err); return ret; } + pstrcpy(bs->backing_file, sizeof(bs->backing_file), + bs->backing_hd->file->filename); return 0; } -- 1.8.1.4