9ae3a8
From b0f9197ca9efa3768253bfab3b938d06e1d2abc1 Mon Sep 17 00:00:00 2001
9ae3a8
From: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Date: Thu, 7 Nov 2013 11:19:18 +0100
9ae3a8
Subject: [PATCH 66/87] block: Don't copy backing file name on error
9ae3a8
9ae3a8
RH-Author: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Message-id: <1383823158-8741-1-git-send-email-kwolf@redhat.com>
9ae3a8
Patchwork-id: 55596
9ae3a8
O-Subject: [RHEL-7.0 qemu-kvm PATCH 25/24] block: Don't copy backing file name on error
9ae3a8
Bugzilla: 978402
9ae3a8
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
9ae3a8
RH-Acked-by: Fam Zheng <famz@redhat.com>
9ae3a8
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
9ae3a8
From: Max Reitz <mreitz@redhat.com>
9ae3a8
9ae3a8
bdrv_open_backing_file() tries to copy the backing file name using
9ae3a8
pstrcpy directly after calling bdrv_open() to open the backing file
9ae3a8
without checking whether that was actually successful. If it was not,
9ae3a8
ps->backing_hd->file will probably be NULL and qemu will crash.
9ae3a8
9ae3a8
Fix this by moving pstrcpy after checking whether bdrv_open() succeeded.
9ae3a8
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
Reviewed-by: Benoit Canet <benoit@irqsave.net>
9ae3a8
Reviewed-by: Amos Kong <kongjianjun@gmail.com>
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
(cherry picked from commit 61ed2684539f7f31304e193d7c0e68d57ce6be88)
9ae3a8
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
---
9ae3a8
9ae3a8
Brewing as: http://brewweb.devel.redhat.com/brew/taskinfo?taskID=6541865
9ae3a8
9ae3a8
---
9ae3a8
 block.c | 4 ++--
9ae3a8
 1 file changed, 2 insertions(+), 2 deletions(-)
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block.c |    4 ++--
9ae3a8
 1 files changed, 2 insertions(+), 2 deletions(-)
9ae3a8
9ae3a8
diff --git a/block.c b/block.c
9ae3a8
index beeb600..dccdb2c 100644
9ae3a8
--- a/block.c
9ae3a8
+++ b/block.c
9ae3a8
@@ -974,8 +974,6 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
9ae3a8
     ret = bdrv_open(bs->backing_hd,
9ae3a8
                     *backing_filename ? backing_filename : NULL, options,
9ae3a8
                     back_flags, back_drv, &local_err);
9ae3a8
-    pstrcpy(bs->backing_file, sizeof(bs->backing_file),
9ae3a8
-            bs->backing_hd->file->filename);
9ae3a8
     if (ret < 0) {
9ae3a8
         bdrv_delete(bs->backing_hd);
9ae3a8
         bs->backing_hd = NULL;
9ae3a8
@@ -983,6 +981,8 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
9ae3a8
         error_propagate(errp, local_err);
9ae3a8
         return ret;
9ae3a8
     }
9ae3a8
+    pstrcpy(bs->backing_file, sizeof(bs->backing_file),
9ae3a8
+            bs->backing_hd->file->filename);
9ae3a8
     return 0;
9ae3a8
 }
9ae3a8
 
9ae3a8
-- 
9ae3a8
1.7.1
9ae3a8