From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43369) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VbuUm-00041p-69 for qemu-devel@nongnu.org; Thu, 31 Oct 2013 11:49:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VbuUh-0004Hr-5t for qemu-devel@nongnu.org; Thu, 31 Oct 2013 11:49:16 -0400 Received: from mx1.redhat.com ([209.132.183.28]:42950) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VbuUg-0004Hi-V4 for qemu-devel@nongnu.org; Thu, 31 Oct 2013 11:49:11 -0400 From: Kevin Wolf Date: Thu, 31 Oct 2013 16:48:25 +0100 Message-Id: <1383234524-372-12-git-send-email-kwolf@redhat.com> In-Reply-To: <1383234524-372-1-git-send-email-kwolf@redhat.com> References: <1383234524-372-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL 11/30] 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